"Every X Seconds" not working in a function

0 favourites
  • 7 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • Hi all,

    I have a game that has multiple levels. Each level has its own timer that controls when the level ends. Because of this, I have externalized the level config into a function that is called at various points in the game. (called initially when the game loads, called when someone restarts a level etc.)

    Unfortunately, it seems that my "Every X Seconds" loop isn't working within the function.

    See the link below for a very basic capx demonstrating this.

    dropbox.com/s/e0b762pbkup6bl3/TestingLoopsInFunctions.capx

    What Should Happen: The text on the main screen should count down from "3".

    What is Happening: The text is sitting on "3".

    Any thoughts on this? I have a feeling I'm missing something very obvious, as I would imagine this would just work.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That can't work. You call a function once, then it returns, so the Every X seconds code won't be called again. Just move the code out of the function. It will only be called if LevelNum=2 anyway.

  • Hm ok good to know. I had a feeling that was the case.

    So then I guess I have more of a "how would you do this" sort of question?

    I have a timer that counts down from 60 for level 1. The level ends, and a screen comes up to tally your points. Then you hit continue, and level 2 begins (same background). I want to repeat all of the previous actions from Level 1, but with a different timer, and different (stronger) enemies...

    Is there a simple way to achieve this? I was originally trying to put the loops into a function so I could say "ok begin level 2 actions."

  • One suggestion: Have a Global for your level. 'On start of layout' setup whatever else needs to be configured, creating sprites, setting values, timers, etc, based on the level number. You can use a function for this (or not). At the end of the current timer, add one to the level counter, and 'Restart layout'.

  • Yep, I messed with it some more, and landed on that. Rather than having a function for each level, I just have a large check for LevelNum, and then each config item is within that conditional statement. Thanks for the help!

  • You can always loop function until it meets certain condition. For example

    -On Function "AAA"

    --If A=\=B ( or any other condition )

    ---do something

    ---- Call Function "AAA"

  • Ah good point. I'll keep that in mind- thanks.

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