How do I make For Loops work instead of writing out.

Get help using Construct 2

Post » Fri Jul 29, 2016 11:41 pm

I think there is something fundamental I missing about how to use 'for loops" in Construct 2.
Wrote two versions of a function, which I think are logically equivalent , but the non-looping version works and the looping version just plays the audio sound once (so I think is just looping once). I know in some programming languages there is a next or an increment, but doesn't seem to be case from looking at system expressions.

Looping version of function
Image

Non-looping version of function
Image



I've had this a couple of other places with using blank sub-events and them not executing in the sequential order I expected (So maybe it is something deeper than me just misunderstanding the syntax of for loops"
B
8
S
2
Posts: 21
Reputation: 509

Post » Sat Jul 30, 2016 12:33 am

Your problem currently is using the "Wait" action, which basically breaks the normal flow of the event sheet.

A loop will run to completion in one frame.

A wait action will basically take what remains of the actions after it out of the current flow of events, and complete them at a later time.

In your loop, there are no actions after your wait, so nothing happens. All four instances of your sound get played in the same frame.

If you use waits, it is best to have all your actions in one event rather than a loop.
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Sat Jul 30, 2016 12:40 am

oosyrag - Thanks that makes sense, kind of understand why a frame based system would do this cause it kind of breaks the event based model. Makes writing clean code a bit tricky. Thanks again.
B
8
S
2
Posts: 21
Reputation: 509

Post » Sat Jul 30, 2016 5:14 am

There are other ways to do loops over time... I just would just use an incrementing counter and/or every x seconds instead of the loop condition. I can make an example for you when I get back to a computer.

Also I tend to avoid the wait action as much as I can, as it is a special case and breaks the normal flow. It has it's uses in the proper situations though.
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Mon Aug 01, 2016 10:33 am

Thank you very much. Worked for this instance and think it is also a key to fixing a couple of other lingering bugs in the code.
B
8
S
2
Posts: 21
Reputation: 509


Return to How do I....?

Who is online

Users browsing this forum: bluesun66 and 2 guests