Is it possible to stack items just using an array?

0 favourites
  • 3 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • I've been spending a long time trying to get this working and I always seem to run into a problem. I'm not even sure if it's possible to stack items into an inventory with the way I've made my game but here's what I've figured out so far:

    I create an array and tiled background for the inventory. When I run into an item I pick it up and then I start a loop. The loop basically goes through each spot in the array and looks for an empty space to place the item.

    Everything up to this point works great but I can't get the picked up item to recognize when I already have the same item in my inventory. I want to make it so that:

    -There can be multiple stacks of an item type with a maximum amount of the item in each stack. (So if I want a stack of bullets the max in one stack can be 10)

    -The picked up item goes to the smallest stack.

    -Shooting a bullet, for example, will take away one item from the stack (assuming the stacked item is a bullet).

    Is this even possible using just an array or am I just driving myself crazy?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • https://copy.com/Tw3lYr2GlJ4AI0aj

    You need some kind of means to keep track of the maximum stack amount for the items (you can save those in a dictionary for example, the dictionary can be filled at the start of your game from a text file). Other than that the array should suffice. You can also add other qualities like description etc to it.

  • copy.com/Tw3lYr2GlJ4AI0aj

    You need some kind of means to keep track of the maximum stack amount for the items (you can save those in a dictionary for example, the dictionary can be filled at the start of your game from a text file). Other than that the array should suffice. You can also add other qualities like description etc to it.

    I'll try it out thanks!

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