How do I use a wait command within a function?

1 favourites
  • 7 posts
  • Hey all! Ok, so I'm trying to make a space invaders clone and an important function freezes after I've restarted the layout/gone back to the same layout. I've done some trouble-shooting and I think it's freezing because of a wait in the function. I found more info on this but I'm unsure how to implement the work around the tutorial mentions.

    Here's a capx and pic of the code with the problem (I think.)

    Essentially, I want the player to be able to pause the game while playing and be able to press the "Home" button to go back to the main menu. I can do this but if I try to replay level one , the game function freezes. How could I properly code this so it doesn't freeze and is reusable for multiple levels.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You should be careful using "Wait" in functions, because it resets local variables and function parameters. But this is not the case here.

    The problem here is that you set time scale to 0 when Pause button is pressed, and it remains 0 even after the game is restarted. That's why "Wait 3" is taking forever.

  • Oh wow. Haha, that was a simple fix. Thank you!

    Ok, would there be another way to accomplish a small wait/pause for x seconds in a function? I'd like to play a small break before and after each level, where the high score is tallied up and you see a short cutscene(still images.)

  • heyguy

    C2 will tell you when an animation is finished...

    in your function you start cutscene animation "Scene01"

    so, outside the function make an event:

    cutscene - On animation "Scene01" finished - (then add all the actions after the wait...)

  • You can use wait in functions, just don't try to access Function.param(n) after the wait.

  • FWIW Construct 3's new built-in functions do now restore parameters after the wait.

  • Thanks for all the help folks! Much appreciated!

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