For loop not behaving as expected

Get help using Construct 2

Post » Fri Mar 15, 2013 4:00 am

[QUOTE=raddevon] OK. This is great feedback so far. It seems the for loop is not a good structure for what I want to do. Does anyone have a suggestion how I could create these sequences of actions then pause for the player to respond?[/QUOTE]


I generally use global variables as flags.

flag = 0 > whatever action you want and set flag to 1
flag = 1 > next action

gazoogle2013-03-15 04:03:11
B
34
S
4
G
8
Posts: 67
Reputation: 5,857

Post » Fri Mar 15, 2013 6:49 am

Yes, that was my theoretical expectation too!! But... in real C2... I just would like to write out the numbers from 2 to 12 on the screen. Sorry, maybe I don't understand the C2 programming logic. It would be realized that way with a common programming software. Please try this at home. No key press, no touch, no mouse.

Strange For-Loop Behavior CAPX



... results in ... Please, note that it starts with 1 and goes to 12!! Furthermore, I'm expecting loopindex to return the numbers 2 to 12.




[QUOTE=ramones] @XManBG It does run exactly 11 times... every time you run that event. If you have it run on key press then it will loop 11 times when you press the key. If you have it running every tick then it will loop 11 times every tick.[/QUOTE] XManBG2013-03-15 07:04:34
B
11
S
3
G
3
Posts: 79
Reputation: 3,343

Post » Fri Mar 15, 2013 6:59 am

[QUOTE=XManBG] Yes, that was my theoretical expectation too!! But... in real C2... I just would like to write out the numbers from 2 to 12 on the screen. Sorry, maybe I don't understand the C2 programming logic. It would be realized that way with a common programming software. Please try this at home. No key press, no touch, no mouse.


[/QUOTE]

Place 'trigger once' or other trigger to your event. Otherwise it will run every tick.
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Fri Mar 15, 2013 7:09 am

Thanks vee41, with trigger once it works as expected. It shows the numbers from 2 to 12 once on the screen.


Anyway I'm really wondering in what situation you could need the For-Loop to runs to eternity and not only once from 2 to 12?! It seams without Trigger once to be unusable?!XManBG2013-03-15 07:13:13
B
11
S
3
G
3
Posts: 79
Reputation: 3,343

Post » Fri Mar 15, 2013 8:41 am

[QUOTE=XManBG] Thanks vee41, with trigger once it works as expected. It shows the numbers from 2 to 12 once on the screen.


Anyway I'm really wondering in what situation you could need the For-Loop to runs to eternity and not only once from 2 to 12?! It seams without Trigger once to be unusable?![/QUOTE]

Many situations! :)

Here is an example project which uses for loop each tick to determine RTS units course of action:

Sidescrolling RTS example
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Previous

Return to How do I....?

Who is online

Users browsing this forum: Khamsou, nedzad and 17 guests