search in array for value

Get help using Construct 2

Post » Mon Feb 03, 2014 3:38 pm

hey guys i am looking for a way to search through a row of a 2D Array, let's say i want to check for every X in Y=4, if the value is "1". and then do an action for every 1 found. i also need to use the x value for the found 1 as an expression.

i have searched through the forum and didnt find something. i haven't got much experience with for-loops, but with arrays.
so i guess the best solution is to do it with a for loop. i tried some stuff but didnt get it to work.

somebody can help?
thanks in advance
phil
B
23
S
6
G
5
Posts: 132
Reputation: 4,487

Post » Mon Feb 03, 2014 3:43 pm

I'd do something like this, but there might be better ways:

for each xy element
system compare two values : Array.CurY = 4
Array compare value = 1

oh in the action following you can use Array.CurX in the expression
LittleStain2014-02-03 15:45:32
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 » Mon Feb 03, 2014 4:00 pm

@LittleStain
thank you once more for your quick answer!
i actually got mine to work right now, seems like i just misschanged something. it looks like this:
system for "check" from 1 to 4
-> [array], Value at (loopindex, 2) = 0
-c> object instance variable = loopindex -> destroy

-c> this is an additional condition and the -> a sub-event. then i threw in some more conditions for everything i want to destroy with the instance variable, which has a 0 in the array at It's X.
B
23
S
6
G
5
Posts: 132
Reputation: 4,487

Post » Mon Feb 03, 2014 4:01 pm

An alternative:
searcharray.capx
ImageImageImage
B
71
S
21
G
229
Posts: 3,687
Reputation: 128,338


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 14 guests