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
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

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 Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

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
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Sat Feb 19, 2011 2:24 am

Don't forget step.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

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
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

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 Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

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
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

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
87
S
21
G
12
Posts: 3,240
Reputation: 16,461


Return to Construct 2 General

Who is online

Users browsing this forum: Tom and 15 guests