How do I setup items to go into inventory in an order

Get help using Construct 2

Post » Sat May 21, 2016 10:31 pm

so i have an array in which items spawn in my inventory my inventory is like 40 spaces

i use parameters

X=array.CurX
Value= array.CurValue +1

and when i click to pick items

it spawns on
layer= Inventory_window
X=inventory_slot_0_0.x
Y=inventory_slot_0_0.x

but if i drag item out of the box i understand that the value of my array when i pick items it wants to keep progressing is there a simpler way of having it check for slot is open and put item in the next open slot so if i put items in slot 123, then take out item in slot 2 . next time i pick an item it goes go slot 4 rather than slot 2.... thats what i'm trying to achieve any suggestions or setups?
B
10
S
1
Posts: 97
Reputation: 700

Post » Sat May 21, 2016 10:43 pm

Plug whatever is the value in an empty slot in your array (I assume you use 0) into the "indexof" expression of the array object like so:

array.indexof(emptyvalue)

This expression will return the index at which the first X axis element matching the criteria is. Or -1 if an empty slot is not found. So in your case you will get the number of the first empty slot, in which you can put an item. Or if the result is -1 you can do some kind of "inventory is full" message.
B
15
S
6
Posts: 85
Reputation: 1,195

Post » Sat May 21, 2016 10:50 pm

this sounds good but if put in

array.indexof(emptyvalue)

wouldn't the items just get set to going into slot 1 even if there is an item there.... seems like i need some setup to check which slots have items and which are free
B
10
S
1
Posts: 97
Reputation: 700

Post » Sun May 22, 2016 9:05 am

Gussy wrote:this sounds good but if put in

array.indexof(emptyvalue)

wouldn't the items just get set to going into slot 1 even if there is an item there.... seems like i need some setup to check which slots have items and which are free


How do mark a slot as empty now? If you have not filled your empty array of size(x,y) with anything there should be a "0" in every empty slot. Look for that 0 with array.indexof(0) and you are good to go. You can also mark empty slots differently, if you want to mark some item with the number 0. But then you would need to fill the array with that value on creation and be careful that only runs once when a new game is started and not on layout start or anything (switching layouts would then delete all values from the array). 0 is a safe bet.
B
15
S
6
Posts: 85
Reputation: 1,195


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 31 guests