Is it possible to stack items just using an array?

Get help using Construct 2

Post » Sun Nov 23, 2014 2:04 am

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?
B
16
S
4
G
4
Posts: 59
Reputation: 3,091

Post » Sun Nov 23, 2014 9:01 am

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.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Mon Nov 24, 2014 12:38 am

mindfaQ wrote: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.


I'll try it out thanks!
B
16
S
4
G
4
Posts: 59
Reputation: 3,091


Return to How do I....?

Who is online

Users browsing this forum: Exabot [Bot], FacuLNF and 71 guests