How do I make my code be able to stack items properly?

0 favourites
From the Asset Store
Stacking tower is a game to try to make the tower higher
  • I'm trying to make an inventory system that can stack items. Currently, the items can be collected, but when I collect the same item I collected before, it only stacks at the first column. Could anyone help me?

    here is the array above (ignore the slots without 0s(I added them))

    the event sheet above

    and the variables I used

    Also, the font that display the amount of items stacked show of the first column as well.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't think it'll recognise loopindex(i) so probably keeps returning 0. I would instead continue using array.curx for the row

  • Now it's only stacked the next slot, that's empty. Also, all the FontInventoryQuantity objects are displaying that

  • Looking at the conditions maybe it needs a bit of work, I think some are not needed. Feel free to share the file and I can take a look

  • accounts.google.com/v3/signin/identifier

    NOTE: the inventory system is on the "HUD" event sheet

  • And where can I test picking up items ?

  • You could test them at the “test” level. In it there are some diferent items. Also, press I to open or close the inventory

  • Ok I tidied it up a little and got it working, take a look here dropbox.com/scl/fi/11t8l53k64av4tggggihq/game_edited.c3p

  • Thank you! Now it's finally working.

  • Hello again now I'm struggling on: when I left click on a item, like a potion, it substract it's amount or, if the amount goes to 0, the item gets destroyed. The problem is: when I add an item again, it's added only on the slot that had the deleted item, so when I get another item, it can't go on front of the last inventory slot

    here is the updated code

    and the code to delete the item, or substract it's amount

  • I can imagine a problem but it doesn't sound like what you described. Because you are always adding 1 to the slot ID and then using this as the next empty one then deleting items in the middle won't work so I can see that you need to rework the empty slot ID logic but you said the problem is its always added on the slot of the deleted item ? So is that what you meant that it doesn't find the new empty slot ?

    To rework that logic to find the empty one you can rather than add 1 to curslotID, add an event to set curslotID to the first column that has 0 amount... so for each x if no item name at curx,0 then set that x to the curslotID. You can add this to top of the function before the other checks.

  • I was saying that when I pick up an item, it was added to the empty slot, but when I pick up a different item, it doesn't appear on the next empty slot.

  • I was saying that when I pick up an item, it was added to the empty slot, but when I pick up a different item, it doesn't appear on the next empty slot.

    That was working in the file I shared though right ?

  • Yes, but I was saying that when I delete an item, it glitches

  • I would expect that to work for the next new item, I guess it breaks for the one after that because it could overwrite the next. If you do the above in my recent post for calculating cur slot ID then it should all come together, there will be no need to set slot ID when you delete the item or add 1 to it, it will just go to the first empty slot each time (assuming that is how you want it in the game)

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