Start/End of layout

0 favourites
  • 2 posts
  • Hello everyone,

    This is my first post on the Scirra forums. I started developing in C2 over a month ago and have not needed to post anything as this community shares so much good content that it was never necessary! Kudos to everyone!

    I have finally not been able to find any useful information regarding the start and end of layout conditions and how they work/are triggered. Here are my issues:

    -"On start of layout" condition seems to trigger before my layout even starts, as though C2 is attempting to prepare the next layout ahead of time. An example of this can be seen if attempting to save data to local storage on start of layout. Here's the example: Game is played in arena. On player "hp" <= 0, add 50 to "experience" variable, go to game over layout. Now on the game over "Start of layout" condition, update local storage to reflect new experience level. What happens is that the local storage will have been updated before 50 would be added to experience, thus no new information is updated to the local storage. Another really simple example of this is attempting to have a countdown start "on start of layout". You will notice your countdown is one second ahead of time (should start at e.g. 90 but is actually already at 89).

    -"On end of layout" condition does not trigger when I leave the layout. The only way I have found to trigger this condition is to restart the layout before I leave it for another layout. What causes a layout to be considered as "ended"???

    Thank you for your help ahead of time!


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I think you are probably confusing a few things.

    What I'm more or less sure about (although I haven't used C2 for a long while) is that the start/end of layout triggers in an expected way.

    // start game

    on start of layout

    every tick


    on end of layout

    // change to other layout

    on start of layout

    every tick


    on end of layout


    now, for your problem with countdown, it doesn't look like a bug really. When you use a digital stopwatch and start it, the first thing that will happen is then millisecond going down, so instantly 90seconds becom 89seconds and some miliseconds

    if your algorithm is something like:

    countDown = 90

    every tick

    -> countDown -= dt

    -> set Text to floor(countDown)

    you'll probably not see 90, and that's ok

    now for the hp problem, I can be that you lose the value of the hp after changing layout, so it's logical that the value saved would be 0

    I don't have enough details to be really conclusive, but if it's something like

    if hp <= 0:

    hp += 50

    go to layout GameOver

    // in layout GameOver

    on start of layout

    save hp to local storage

    and your hp saved is 0, it might be that either hp isn't a global variable (local variable of the same name?), or, that something else is touching it before you're saving it

    also, it's weird that you save the hp in the other layout, it looks more consistent to save the variable at the same place you update. But missing too much context to be really sure.

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