Loop Events

  • How do you loop 1 event with several timed actions?

    I know I've been doing this the hard way for the longest time. What I would do is this:

    On start of layout > Do these 10 actions that take 10 seconds

    And then:

    Every 10 seconds > Do these 10 actions again that take 10 seconds

    Can someone show me a better way?

    Tagged:

  • Every 10 seconds seems fine? You could also put them in a function which runs a 10s timer at the end and say on timer finished : run function.

  • 10 seconds isn't a lot, but I was only using it as an example. Some of my events have over 30 actions timed out. I was just thinking there was an easier way to get it done, but I guess not. Copying and pasting an event and changing On Start of layout to Every X seconds isn't really that much more work. It would be nice though if the was a "Loop after event completes" condition though.

    Thanks for the help!

  • I believe you can use the system "while" condition, but not give it a condition. In this case it basically repeats forever, or until "stop loop" is called. This is blocking, so it's not ideal. But you can add "wait" actions within it to add pauses, allowing you to schedule things to happen at certain times. The expression unblocks during the wait actions, so it shouldn't be a problem.

    while {
    	doThingA()
    	wait(1)
    	doThingB()
    	wait(1)
    	doThingC()
    	wait(8)
    }
    

    You should be careful with this sort of loop, if you forget the "wait" actions it will block the thread and softlock the window. When you using preview that can sometimes softlock the editor as well, as under some circumstances they share the same process.

  • I think I tried that while back but with a global variable condition. I just figured I wasn't using it correctly.

    I tried it alone as you suggested, but with more wait actions, and even though I can hear the game music, I still get a black screen. After a few minutes I get a popup telling me that the webpage is slowing down my browser.

    I'm fine with having 2 long events. If I do things over and over again, I like to find more efficient ways of doing them, but in the end it's really whatever works. I just put them into a group, collapse it and forget about them while I work on other things.

    I appreciate the help.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Actually there is exist a nice and easy solution to your problem. That is: Recursion.

    You can have all the set of actions in a Function. Then at the end of that function, within the function call that function again. It's like an artificial loop. And (optionally) you can stop that loop (recursion) anytime by not calling the function again using an if condition before calling the function each time.

    On Func:
    	Action1
    	Wait 1 sec
    	Action2
    	Wait 3 sec
    	.
    	.
    	ActionN
    	Wait 1 sec
    	Call Func
    

    Unlike your existing version where if you add/remove a bunch of actions, you'll have to re-sync the "Every X seconds" accordingly.. . but here, you can feel free to add/remove anything, your function will be called at the end, to repeat the loop.

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