# Nested loops about same type of object? [resolved]

Get help using Construct 2

### » Tue Apr 29, 2014 1:35 pm

Hi!
Let say I have this :

For each Kangaroo
(sub event) For each Kangaroo

How can I make comparisons between the kangaroos from the first loop and those from the second one?

I'm tyring to do this kind of stuff since yesterday and it makes my brain hurt.
Last edited by Coin-coin le Canapin on Tue Apr 29, 2014 8:26 pm, edited 1 time in total.
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

### » Tue Apr 29, 2014 1:38 pm

Why would you want to do this?
B
14
S
3
G
1
Posts: 255
Reputation: 2,027

### » Tue Apr 29, 2014 1:39 pm

You can't compare two instances directly. You can do it with Families. Otherwise you need to store the relevant data to compare in local variables after the first For, do a Pick All (assuming All is the default pick), then the second For, and do your comparisons against the local variables. It takes some work.

Edit: you should explain what you are trying to do. There may be an easier way.
B
71
S
22
G
281
Posts: 3,842
Reputation: 154,886

### » Tue Apr 29, 2014 2:09 pm

My object is actually not a kangaroo, but a wall.
Basically, what I'm trying to achieve is :

"if a wall A has another wall B directly above it, make A red". I use a grid so my walls are well aligned.
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

### » Tue Apr 29, 2014 3:22 pm

In that case, you can use a 'For Each ordered' to place all walls in order. The trick is to get the right expression. If you normalize all indexing to your grid, it's easier to conceptualize. Assuming the grid is zero based, and your grid is 32, your expression would be something like: (Wall.X / 32) * 1000 + (Wall.Y / 32). What this does is order by column then row, using a large number (1000) to ensure each column is going to index beyond the height of the grid. Now every wall is in order, you just keep track of if there is a wall, in the same column, before the current wall, and set it to red. Again, use local variables to store the 'previous' walls details.
B
71
S
22
G
281
Posts: 3,842
Reputation: 154,886

### » Tue Apr 29, 2014 8:25 pm

Hi!
It took me some time to figure out how to do this with your advice (and to understand the "*1000" purpose), but I finally did it.

previousWall_X = 0
previousWall_Y = 0
For each [wall] order by ( wall.X / wall.Width ) * 1000 + ( wall.Y / wall.Height )
Pick wall where Y = previousWall_Y + wall.Height --> wall set animation to "block" (different hitbox)
(no condition) --> system set previousWall_X to wall.X
(no condition) --> system set previousWall_Y to wall.Y

Thank you very much !
B
12
S
7
G
7
Posts: 450
Reputation: 4,276