for loop

Get help using Construct 2

Post » Thu Jun 20, 2013 1:08 am

Hi

Is there a way to use conditions in for loops, like:

for (int ytemp = y; ytemp > (y-ylen); ytemp--)

Or at least a way to have the loop count backwards, like from 10 to 1 (instead of form 1 to 10) ?     
B
7
S
3
G
3
Posts: 53
Reputation: 2,459

Post » Thu Jun 20, 2013 5:47 pm

Did you try changing the 'for' and 'to' parameters? If it works in Javascript, it (should) work in C2.
B
92
S
30
G
24
Posts: 3,191
Reputation: 32,584

Post » Thu Jun 20, 2013 6:01 pm

@sqiddster I just tried
For "loop" from 100 to 0: append text "loopindex"
And it doesn't work. If I change it to "from 0 to 100" it works, meaning for loops don't count down, which it should
B
83
S
22
G
15
Posts: 1,039
Reputation: 15,209

Post » Thu Jun 20, 2013 6:09 pm

@7soul ,I think it's because it's an inclusivee loop , you may need a variable counting from 100 to 0 to get that count down ...



Whiteclaws2013-06-20 18:11:34
B
38
S
16
G
17
Posts: 2,230
Reputation: 17,220

Post » Thu Jun 20, 2013 6:13 pm

I'm pretty sure I read somewhere that for loops in C2 don't count backwards, can't seem to find where though.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Thu Jun 20, 2013 6:18 pm

Oh, that's interesting.
B
92
S
30
G
24
Posts: 3,191
Reputation: 32,584

Post » Thu Jun 20, 2013 6:39 pm

I don't really see why you'd need it though. If you use a variable containing the end value for the loop, you can just do "variable-loopindex" and it'll start on the variable value and count backwards to 0.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Thu Jun 20, 2013 9:56 pm

@Nimtrix
For convenience, I guess. Like using the "set position" action, instead of "set X" and "set Y"
B
83
S
22
G
15
Posts: 1,039
Reputation: 15,209

Post » Thu Jun 20, 2013 11:10 pm

@7Soul:
Yes, of course. I just meant if there are issues with backwards loops, it's not really a big deal since it's an easy workaround. But it would of course be more convenient to have the option.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Wed Sep 18, 2013 5:07 am

@Ashley - Can you clear this up for us, please? :)
I'm seeking Narnia. Who wants to come with me! Aslan is on the move!
B
127
S
21
G
8
Posts: 759
Reputation: 14,327

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests