Need help with taking items out of array (chest/loot inventory) & putting item into hovered Slot

0 favourites
  • 6 posts
From the Asset Store
Perfect, complete, easy to use to use, out-of-the-box inventory system
  • I wouldn't post this, but I am days on these 2 problems. I would really appreciate some help, I have even redone the entire inventory system from scratch, and it still doesn't work for me. I am still practicing my array skills, so sometimes I encounter issues like this that I think should work, but can't.

    First issue:

    Where: In Event Sheet called Chests, line 6 - marked with a bookmark.

    What is going on: I have a simple inventory using an array called arr_Chest. I made it so you can put items into it, but when I try to take stuff out onto my mouse (with InventoryManager.itemType, .handAmount which then creates a ground item, sets bool pinned true so you can move it around on screen and drop it or place it into your player inventory), it won't work and I really cannot figure out why it is.

    Important: Since I couldn't create a version where LMB click is working, I did it with RMB just to show what I am trying to achieve [on line 6 Conditions]

    I would really appreciate if someone manages to figure out a new way, it's only a line of code that I think is the problem.

    Second issue:

    Where: Event Sheet called Inventory, Line 24 and then Line 39, also bookmarked.

    What is going on: I have a simple player inventory using an array called Inv.

    On line 24: I am trying to check if the function AddToInv has 2 or 3 parameters, the third param is for putting items into a specific Slot which you hover and if you have 2 params then it does it automatically.

    On line 39: I just call that function with 3 parameters.

    project file: ufile.io/0i36w3c2

    Tagged:

  • First issue : easy enough to fix, on line 6 for inventory manager it should be arr_chest.at(chestslot. You have used arr_chest.at(slot

    Second issue : bit more complex but because you are checking if items are in your inventory before calling function addtoinv, rather than inside it like are doing when you initially add the item, then the function paramcount=3 checks should not be inside the loop through all X, because if you add logging you can see it eventually changes all params to 0. I think if you pull the function paramcount=3 checks out of that loop but still inside the function it should be fine, because you have already done the 'is the item here' checks at line 39. I might be wrong on that as it's a little convoluted with the logic but that might be correct.

  • Wulfy

    just saw plinkie beat me to it while I was typing but I had just uploaded my take on it so I will put in my 2 cents :) - it seems slightly over complicated to me... (I am not convinced you need the arrays and I think it could be simplified in a few ways)

    anyway, there is a second problem with event 6 - it moves the grounditem out of the chestslot, but then all the conditions for event 7 are true, so it puts it right back into the chestslot. (with a left click)

    make the first action of event 6 say "Wait 0 Seconds"

    that delays the actions until the end of the current tick - which will happen after event 7 has been checked.

    the other problem was a lot more subtle... there were a couple issues: it was looking for an empty slot before you were checking for 3 parameters, so it has already added it to a slot. And you were passing in invSlot.SlotID instead of Slot.SlotID, and if the slot was empty, after calling the AddToInv function, all the conditions for event 41 were now true, so it tried to add it again, but the handAmount was now 0...

    https://www.rieperts.com/games/forum/newproject.capx

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • AllanR

    Thank you guys so much I really appreciate it, was starting to lose my mind over it! Unbelievable that I didn't see that it was Slot instead of chestSlot as well, no matter how many times I check through things my autopilot still kicks in. I see now, thanks to you what the problems were. These subtle things are the toughest - at least to me, especially Order of Operation if that's how it's called

    Out of curiosity AllanR - how would an inventory be possible without an array, frankly I cannot even imagine that. And how could you actually simplify it? I know that my code is quite messy, so I always like getting some criticism and look at stuff from different angles to improve.

  • Wulfy

    well, there were a lot of bases to cover to make sure everything works consistently and is fairly intuitive. I didn't use any arrays... although I do really like arrays and use them all the time. Using an array makes doing save games easier, and helps when changing from level to level, but sure make code harder to read! I like the way you used the InventoryManager sprite. I also do that a lot - usually when I have multiple groups of items that each need their own group variables. (although I didn't end up using that here either).

    https://www.rieperts.com/games/forum/inventory.capx

  • Definitely a cool system, thank you for showing it off! I like the idea of Slot and Item family, it's probably something I will need to implement into my project too cause at one point, a forge will have its own slots, an oven etc. and then I would need a separate system for each which is a pain. Might consider not using arrays next time around, it's a lot less controllable with them :P

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)