How do I Properly Use Array Conditions

Get help using Construct 2

Post » Wed Aug 12, 2015 10:16 pm

Hello, I've run into a couple of problems enough times to think that I must be doing something wrong, or there are unusual limitations in how arrays work. Here's a couple of examples: 1) I have an array with data set up in it and I can use an action to tell me the value at a location in the array with no problems. But if I try to use the array location in a condition like "array: If value at (x,y) = 1, then... do this", it doesn't work. 2) If I try to combine actions into something like "multiply the value at array (x,y) times 2", it doesn't work either. For 1) I have to first set the value at (x,y) into a local variable and then use THAT in the event's condition. For 2), I have to use two actions: "set the value at array(x,y) to a local or instance variable and then use a second action to multiply or manipulate the value saved.

Is this the norm?

Also, how and when would you use the condition: Compare Current Value?

Thanks
B
4
Posts: 29
Reputation: 264

Post » Wed Aug 12, 2015 10:20 pm

try using a "compare 2 variables" condition instead, and compare Array.at(x) = 1 instead

does that work?

also, try putting the "do this" in a sub event instead.
B
87
S
44
G
16
Posts: 1,009
Reputation: 17,946

Post » Wed Aug 12, 2015 10:25 pm

ImageImageImage
B
71
S
22
G
247
Posts: 3,753
Reputation: 137,552

Post » Thu Aug 13, 2015 12:18 am

Ok, upon further testing, I've found that if you actually set the value immediately before, and then you test the value in a subevent of said event, like BlackHornet did in his example above, then it does work. BUT, if I've loaded the values into the array from a .json file in a previous function and now I'm just comparing a value in the array, it still isn't working. Any action that reads the array works fine, but the condition comparing the value at xy to a set value isn't working. (I think I forgot to mention that the array was loaded from a .json file in my original post...)
B
4
Posts: 29
Reputation: 264

Post » Thu Aug 13, 2015 12:54 am

ImageImageImage
B
71
S
22
G
247
Posts: 3,753
Reputation: 137,552

Post » Thu Aug 13, 2015 1:03 am

Ok, I made an example of what I'm doing. Maybe you can point out what I'm doing wrong: https://www.dropbox.com/s/rvjnr3h59yq2k ... .capx?dl=0

Thanks
B
4
Posts: 29
Reputation: 264

Post » Thu Aug 13, 2015 1:10 am

"A" is not a valid JSON string. Have a look at my example. If you want to initialize the array, do so as I did in the first example and then save that AsJSON, then load that from WebStorate to get it back.
ImageImageImage
B
71
S
22
G
247
Posts: 3,753
Reputation: 137,552

Post » Thu Aug 13, 2015 1:25 am

I think I see now - you want Load from JSON: WebStorage.LocalValue("A")
ImageImageImage
B
71
S
22
G
247
Posts: 3,753
Reputation: 137,552

Post » Thu Aug 13, 2015 1:54 am

I must apologize. I linked the wrong example file for you to see. Here is the correct one, based on your example you sent earlier: https://www.dropbox.com/s/r4hj8pspx3mot ... .capx?dl=0

Thanks again
B
4
Posts: 29
Reputation: 264

Post » Thu Aug 13, 2015 2:06 am

Your data is all in quotes which makes them strings, so comparing against a number won't work. Either compare to "10" or get rid of the quotes to make your data numbers.
ImageImageImage
B
71
S
22
G
247
Posts: 3,753
Reputation: 137,552

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 12 guests