Weapon array not returning values

Get help using Construct 2

Post » Sun Dec 27, 2015 12:43 pm

Trying to figure out how to set the default ammo amounts, I have a counter that should return the value to the HUD here:
Image

And here is the array, I'm playing around with the cells, trying to figure out how to bring in the right value:
Image

Where am I going wrong?
B
39
S
12
G
14
Posts: 1,110
Reputation: 11,184

Post » Sun Dec 27, 2015 1:12 pm

Depth of your array has to be set as least to 1, otherwise the whole array has no size. You can see that, if you look at your array in debug.
B
23
S
3
G
1
Posts: 412
Reputation: 2,062

Post » Sun Dec 27, 2015 3:23 pm

Asmodean wrote:Depth of your array has to be set as least to 1, otherwise the whole array has no size. You can see that, if you look at your array in debug.

Thank you! I was thinking the depth started at 0, so it works now! I was thinking it might be better to switch weapons by pushing the array, I think that's what it's called? Where you shift the cells in a cycle, so the game reads from the fixed cell, but the array shifts the cells around. Would that be a better way of doing it? And I should I be doing all this on every tick for performance?
B
39
S
12
G
14
Posts: 1,110
Reputation: 11,184

Post » Sun Dec 27, 2015 3:23 pm

Asmodean wrote:Depth of your array has to be set as least to 1, otherwise the whole array has no size. You can see that, if you look at your array in debug.

Thank you! I was thinking the depth started at 0, so it works now! I was thinking it might be better to switch weapons by pushing the array, I think that's what it's called? Where you shift the cells in a cycle, so the game reads from the fixed cell, but the array shifts the cells around. Would that be a better way of doing it? And I should I be doing all this on every tick for performance?
B
39
S
12
G
14
Posts: 1,110
Reputation: 11,184

Post » Sun Dec 27, 2015 8:53 pm

I'm not certain if I understand correctly what you think to achieve by using an array. An array is useful if you don't want to deal with a huge amount of variables or you need something that change its size dynamically. Also you can go through all elements of an array very easily. A bad Idea is to change the size of an array every tick by inserting or deleting elements. It will have to reorder the index. Depending of the size of the array it could take some time to do this.
If you store all your Weapons by name or number in an array in the beginning and you want only to cycle through the weapons in the game, you can do this by using the index or use the 'for each element' loop to go through all weapons at once, but I wouldn't use push and pop.
B
23
S
3
G
1
Posts: 412
Reputation: 2,062

Post » Sun Dec 27, 2015 11:34 pm

Asmodean wrote:I'm not certain if I understand correctly what you think to achieve by using an array. An array is useful if you don't want to deal with a huge amount of variables or you need something that change its size dynamically. Also you can go through all elements of an array very easily. A bad Idea is to change the size of an array every tick by inserting or deleting elements. It will have to reorder the index. Depending of the size of the array it could take some time to do this.
If you store all your Weapons by name or number in an array in the beginning and you want only to cycle through the weapons in the game, you can do this by using the index or use the 'for each element' loop to go through all weapons at once, but I wouldn't use push and pop.

Excellent, I'm using a global variable to control which column is being shown, so that confirms I shouldn't be pushing and popping. Here's the finished result: how-do-i-tidy-up-keypress-and-variable-ranges_p1002149?#p1002149
B
39
S
12
G
14
Posts: 1,110
Reputation: 11,184


Return to How do I....?

Who is online

Users browsing this forum: Armored Pig DEV, bbjGames, Dain, LaurenceBedford, lucstanislash, OddConfection, Yahoo [Bot] and 10 guests