How do I put a value in a unknow index of an array?

Get help using Construct 2

Post » Sat Sep 26, 2015 3:37 pm

I've already read all the tutorial on the array and inventory sistem but i can't figured out this: when the player grab an object, this should be put inside in the invetory firts slot avaible but this happen;

Image
The object fills all the slots in invetory. This is the code i use:

Image

The logic i still looking for is: grab the item, is the first slot avaible? yes put in that, else check for the next one.

Please help!
B
3
Posts: 7
Reputation: 189

Post » Sat Sep 26, 2015 6:01 pm

I don't understand. Do you stack items? Then you are missing the amount of each item in the slot. Do you not stack items? Then why not just add the new item at the end of the array, because obviously all previous slots will be filled.
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 » Sat Sep 26, 2015 6:11 pm

The for each command is doing that. That is why it is filling it up your commanding it to put it in each slot. You should check for the first empty slot and place it there.

So 'for each' then to a check for if the current slot is empty if so break out the loop and place it there.
B
23
S
4
G
2
Posts: 364
Reputation: 2,392

Post » Sat Sep 26, 2015 6:24 pm

see.... if this helps you

Example.capx

Image
Image
B
65
S
23
G
7
Posts: 1,504
Reputation: 10,894

Post » Sat Sep 26, 2015 9:04 pm

korbaach wrote:see.... if this helps you

Example.capx

Image



Thank you for the example, it's self-explanatory. It's still not helping me becouse, in your example the intial array width is 0 and you use push back to create a "slot" and the expression"Set value at (ArrayPicked.Width-1, 1) to 1" to put the value, whic is great but, in my case, i already know how many slot i have in my invetory. Any way, it's a great idea.


PhoenixNightly wrote:The for each command is doing that. That is why it is filling it up your commanding it to put it in each slot. You should check for the first empty slot and place it there.

So 'for each' then to a check for if the current slot is empty if so break out the loop and place it there.


How can i break the loop?
B
3
Posts: 7
Reputation: 189

Post » Sat Sep 26, 2015 9:19 pm

pj4ever wrote:.. in your example the intial array width is 0 and you use push back to create a "slot" and the expression"Set value at (ArrayPicked.Width-1, 1) to 1" to put the value, whic is great but, in my case, i already know how many slot i have in my invetory...


I use " o width" and "push" because I dont know how meny slots you have in inventory... :D
Image
B
65
S
23
G
7
Posts: 1,504
Reputation: 10,894

Post » Sat Sep 26, 2015 9:33 pm

ImageImageImage
B
71
S
21
G
230
Posts: 3,688
Reputation: 128,852

Post » Sat Sep 26, 2015 10:15 pm

They System have a Stop Loop action. But it appears to not being doing what it says and stopping the loop. I wonder if its a beta thing.
B
23
S
4
G
2
Posts: 364
Reputation: 2,392

Post » Sat Sep 26, 2015 11:17 pm

korbaach wrote:
pj4ever wrote:.. in your example the intial array width is 0 and you use push back to create a "slot" and the expression"Set value at (ArrayPicked.Width-1, 1) to 1" to put the value, whic is great but, in my case, i already know how many slot i have in my invetory...


I use " o width" and "push" because I dont know how meny slots you have in inventory... :D



You're right indeed but, the inventory could have any width, e.g.: a bag contain 10 spaces but i wanna make it bigger, than i buy a new one with 20 spaces. Your solution is pretty cool (i will quote you if my game will see the light!).




I've try this kind of code early but i think that the "stop loop" doesn't do anything, just as
PhoenixNightly
say.

Thank you guys for the answers. If i discover something, i will share in the tutorial section 8-)
B
3
Posts: 7
Reputation: 189

Post » Sun Sep 27, 2015 1:00 am

You can try this
Image

You a variable to make when it set within the loop so it won't keep setting.
B
23
S
4
G
2
Posts: 364
Reputation: 2,392

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests