Inventory wthout arrays

Get help using Construct 2

Post » Fri Nov 13, 2015 12:28 am

So i want to avoid using arrays because I have so little experience with it.

ok so I created a batch of two item to be picked up one is Berry and one is pokeball (yeah you can guess what it does it pokes the ball lol )

And i have a bag with Ten slot they are text based family.

so Far I have it working correctly as far as making it pick the slot and placing the variable where it need to be at except for one thing when I go to place a 2nd item berry to be picked up....Now it used up the third slot ...so it look like this:

Berryx3
Pokeballx3
Berryx3

That isnt what i want what i would like it to do is

Berryx6
Pokeballx3

And I cannot for the love of my life figure out how to Tell contruct that IF Berry is already in the inventory list Just add to the existing instead of going to the third.

And yes I would like to use family method because all the item are really stored in a single chest like orb family style

And this is like the last part of the game mechanic I have to do left for this game. If you guys insist that I should use array Id like some help learning it. :D
B
52
S
24
G
6
Posts: 391
Reputation: 7,855

Post » Fri Nov 13, 2015 8:59 am

From your explanation it is unclear to me how you have this set up..
How would the program know you already have berries and how many you already have?
Are you using variables to keep track of this?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Nov 13, 2015 7:15 pm

The Textbox object has two variable. One variable is name Item_name, the value of it on default is none. and the other variable is Item_slot and this value is starting at 1 to 10. Because there is ten textbox object in the inventory screen.

I have the game picking the textbox object based on the Item_slot number and then Add one to the localvar.item_slot so that It can begin picking on the next new item.

I went ahead and change the quantity value from the chest orb to add to global variable. Before I saw that by using the chest own value was pretty stupid as it resulted in the berryx3 twice.

And the "How many" I am using a global variable for each item. so the Textbox event would have set text (self.item_name&"x"&Globalvar.Berry)

And the event runs like this If chest orb is pickedup And pick Textbox object based on localvarholder.item_slot (Then sub event)Chest orb variable item =berry then set value textobject.Item to Berry and then add one to localvarholder.Item_slot.

Its right here I cannot figure out how to tell Construct if one of the textbox object.Item already have the value Berry to not make the other textbox object.item value change.

I suppose i could use a series of group event but that would be silly to have each group event for every first time item and have it deactivate. But that would mean twice as many event or maybe triple the events.
B
52
S
24
G
6
Posts: 391
Reputation: 7,855

Post » Fri Nov 13, 2015 8:27 pm

https://www.dropbox.com/s/1281a7f47p9wz ... .capx?dl=1

This will auto download.

Um i havent set the text to anything yet because I am so mad and wondering why doesnt contruct two doesnt see that there is already a textbox object already with the item berry.

Ive even tried to make a if texbox has berry do nothing It still pick the next one. What am i doing wrong >< or am I missing a particular event ?
B
52
S
24
G
6
Posts: 391
Reputation: 7,855

Post » Fri Nov 13, 2015 9:53 pm

Hmm, I'm not sure pick all does what you seem to expect it to do, I've always assumed it doesn't do that and used for each loops.
But I'd seriously recommend using arrays they are a ton easier once you understand them.
Here's an example of how your inventory could be done with an array.
https://dl.dropboxusercontent.com/u/6026058/Top_down_rpg_with_array_inventory.capx?dl=1
B
17
S
6
G
1
Posts: 41
Reputation: 1,725

Post » Sat Nov 14, 2015 1:22 pm

@Maukka Ok so i saw the changes you did and I am surprise how the array code you have shown me to be that much more effective then what i originally had. Question I saw that in the arrary property the Width height and depth

I am assuming Width is X value Height is Y value and depth is Z value. I see that width is 10 and height is 2. I see that the width is in corresponding to the inventory limit but why is the height at 2 ? And Will this and yes i do want the limit to be ten slot inventory.

And that text box code (new line) I did not know that was possible I see now why array is much easier for inventory

And i saw that in the Action code there is these "Cur" code what is that ? Is it Current ? or Curse ?
B
52
S
24
G
6
Posts: 391
Reputation: 7,855

Post » Sat Nov 14, 2015 2:22 pm

Height is 2 because you want to store the item name and amount of items separately, (you could have them as one but you'd have to turn the amount back into number to add to it ie. int(right("berry x 3", 2)) and... anyway you want 2 columns)

CurX, CurY and CurValue are current thing in a for each loop. You see them if you look at expressions that an array has.

Also if you run in debug mode and select the array you can look at how it stores the data. it should show something like
(Berry, 3)
(Pokeball, 6)
(0,0)
(0,0)
and so on, it might help with visualizing how the array works and such.

As an aside if you didn't want a inventory limit you could use 0 width array and a push action to increase the size of the array whenever you add items
B
17
S
6
G
1
Posts: 41
Reputation: 1,725

Post » Sun Nov 15, 2015 12:47 am

What about if your first item runs out to 0 how would i shift the inventory without having a bunch of blank spot ?
B
52
S
24
G
6
Posts: 391
Reputation: 7,855

Post » Sun Nov 15, 2015 12:00 pm

Sort it, it'll do it alphabetically, if you want to keep it in pickup order or some other you'll need another field(more height) to keep track of it.

Sorting X will use (X,0) to sort it, if you want to sort by quantity or something else you can do some stuff to have it temporarily be at (X,0)

Also you could do a "for each X element" loop that checks for 0 and after it set every non 0 entry to be curX-1 but I find that more annoying to do.
B
17
S
6
G
1
Posts: 41
Reputation: 1,725


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 28 guests