I don't get loops

For questions about using Classic.

Post » Thu Jan 22, 2009 10:41 pm

Hi!
I don't get loop.
How do I use them?
Can anyone upload an exsample .cap with some comments?
B
33
S
15
G
6
Posts: 242
Reputation: 4,343

Post » Thu Jan 22, 2009 11:01 pm

They're really simple. They just repeat stuff.

+ On spacebar pressed
+ Repeat 5 times
-> Add 1 to global variable 'test'

When you press spacebar, 5 is added to 'test' (it adds 1 five times, instantly)

+ Start of layout
+ Repeat 100 times
-> Create Star at random(640), random(480)

Creates 100 randomly positioned stars on startup.

There are some variations like For (loop over a range of numbers), For Each (repeat once for each instance of an object), and so on. You can read more in the Conditions article.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Thu Jan 22, 2009 11:11 pm

Okay, probably you may want to wait for some brainiac to explain it to you properly. And as I'm writing this I'm noticing mighty Ashley replying... I'll still reply anyway. :D

I'd say you need loops where you want certain events/actions being executed many times a tick, instead of only once.

I have uploaded a little example for you with a WHILE loop. We have a Global there called Outcome and we want it to have the value 0,1,2 or 3, which is Random(4) of course. But we also want to be able to dynamically exclude certain possibities. We define these with the Nono_a and Nono_b globals. The values set there are values Outcome must never have. So we cannot simply run Random(4), but we run it until the result will be different from Global Nono_a+b. And all this will happen in the same tick, thanks to the while loop. :)

So if you run the example hit X and you will see the value will always be different from the ones defined in the Nono globals.

I hope that was some help at all... maybe this example was horribly lame.
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Thu Jan 22, 2009 11:21 pm

Thanks:) Now I get it. It has been a mystery to me since my MMF-days :oops:
B
33
S
15
G
6
Posts: 242
Reputation: 4,343


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests