Customized Loop Iterators

Discussion and feedback on Construct 2

Post » Fri Feb 18, 2011 11:32 pm

I was thinking the other day about how nifty it would be if you could use a custom iterator for For loops, that way you could have loops that iterate backwards or increase 2 at a time, etc. And if you want to keep for loops simple, maybe this could be split off into a separate event.

Either way, I think it would be nifty.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,096

Post » Sat Feb 19, 2011 12:05 am

secondededed

A check box for ascending/ descending, or even a flag on a for loop would be awesome.
Image ImageImage
B
165
S
49
G
147
Posts: 8,047
Reputation: 96,586

Post » Sat Feb 19, 2011 1:00 am

One way it could work, is 4 parameters
Iterator name, initial value,
Comparison combo box(greater than, less than, equal, not equal to, etc),
And final value

Then the iterator would be declared and behave as any local variable, to be manipulated through actions, and compared before each iteration
Spriter Dev
B
96
S
21
G
12
Posts: 3,259
Reputation: 16,819

Post » Sat Feb 19, 2011 2:24 am

Don't forget step.
Image ImageImage
B
165
S
49
G
147
Posts: 8,047
Reputation: 96,586

Post » Sat Feb 19, 2011 4:16 am

For now, we can do something like this:


+ System: For "loop" from initial to final
+ System: final Greater than 0
+ System: (LoopIndex) % step = 0
-> System: do actions


I did an example to illustrate my thoughts. This is the link: http://dl.dropbox.com/u/7967934/Iterati ... ve_0.x.cap

Hope it helps someone.
B
50
S
16
G
7
Posts: 59
Reputation: 6,365

Post » Sat Feb 19, 2011 2:05 pm

This should all be doable with an extra 'step' parameter, right?

For 1 to 10 step 2, or for 100 to 10 step -5, and so on.
Scirra Founder
B
382
S
223
G
86
Posts: 23,991
Reputation: 189,739

Post » Sat Feb 19, 2011 3:23 pm

Yes, but what about for x = -100 to 0 step 5?
Could we do that too?
Image ImageImage
B
165
S
49
G
147
Posts: 8,047
Reputation: 96,586

Post » Sat Feb 19, 2011 4:10 pm

...yep... you'd just put -100 as the start, 0 as the end, 5 as the step...
Scirra Founder
B
382
S
223
G
86
Posts: 23,991
Reputation: 189,739

Post » Sat Feb 19, 2011 5:25 pm

Yeah, should be good. Only thing you couldn't do is change the stepping method mid loop, or change the iterator upon a certain condition. Would it be possible to make loopindexes actual local variables ashley?
Spriter Dev
B
96
S
21
G
12
Posts: 3,259
Reputation: 16,819


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 7 guests