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

0 favourites
  • 5 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • 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

    Non-looping version of function

    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"

  • 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.

  • 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.

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)