Need help for a simple inventory system?

0 favourites
  • 7 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Hey folks!

    I've read a lot of array tutorials etc but i've been stuck on this inventory feature, it's pretty much the first time I'm doing one of these.

    My inventory is a fixed 6 slot INV made of 6 instances of an object called InventorySlot. the object has 3 variables : ID, Content, and an "full" bool to check its state.

    I also have an array called "INVArray" with 6 elements.

    The idea is that, when I pickup an item on the ground, I fetch the item name (stored in a instanced string) and store it in a global var "itempickedup".

    When the item is picked up, it triggers a function CheckInventorySpace that, in theory, should loop for all 6 elements of the array, find the first cell available, check if it is empty, and set its value to "itempickedup". But it doesn't work!

    I manage to update the first cell and send the item name to the array, but it won't work after that.

    What am I doing wrong?

    Thank you in advance!

  • There is no condition to check if it's empty. if array.at(loopindex) = "" or something like this

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey, thanks I wasn't aware of this! I switched the function to this but it still doesn't work, I feel like something is missing. I did check in debug mode and the global var "itempickedup" is updated correctly so it should be able to send the right information to my array?

  • Are the empty cells 0 or just empty. If empty you need to use "". Also you removed the stop loop action but you will need that or it will fill all empty cells with the variable instead of the first one found.

  • the empty cells have 0 by default, I checked in debug + tried switching to Value at INVArray.At(Loopindex) = "" and it wouldn't even send data to the first cell anymore. Even with the stop look it won't fill all empty cells, just the first one?

  • as if the loopindex wasn't working? I'm not sure

  • Oh you switched to using the array instead of system conditions now. Instead of loopindex you can use the array condition 'compare current value' of X.

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