How do I change global variables before including an event sheet?

0 favourites
  • 7 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • Hi -

    This is a newbie question: I can't figure out how to update global variables on an event sheet before I include another one.

    Say I have a layout that should update some globals I set earlier (level number increase, number of enemies increase, etc.) before going on to the displaying and the mechanics of the game. Like this:

    In that layout's event sheet I set System > On start of layout > Set variable to x, above the rest of the included event sheets (for displaying and the mechanics of the game), but the events in those included event sheets still use the default global variable values.

    Are includes not synchronous? I'm sure there's a simple answer for this but I can't seem to find it. Thanks :)

  • Im not good with that but i think the include event sheet start first even if its down of some events.

    You have to deal with system -> set group active.

    So create a group with the update variable you want and set it active the time you want, also deactivate it "unchecked the active on start".

  • I just tried it and it works as expected: https://www.dropbox.com/s/2m5df288h640h0o/New%20project%20%285%29.c3p?dl=0

    So if something's wrong, it's probably not this.

  • I must be misunderstanding how Construct deals with the start of layout condition, then.

    To recreate what's happening in my game with what you put together Ashley, if you take the "Set text" action you have in sheet 1 and paste it to sheet 2, then change the condition from every tick to start of layout, you'll see the variable reverts back to the default, even though we set it earlier.

    That's analogous to what I'm trying to do - update game level variables from the default sheet for the layout, then include the other sheets that use those new values. It doesn't seem like I can set them without adding some kind of delay or something in between sheets.

  • ^ I forgot to mention that in my example you'd also put the global into a third sheet, like this:

    dropbox.com/s/kpvcz4aovprg4gn/New%20project.c3p

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well now you have two 'On start of layout' triggers, one which sets the variable, and another that gets it. It works if it does set then get, but it doesn't work if you get then set. So you've created a dependency on the order on which Construct runs 'On start of layout' triggers. It's best to avoid depending on internal details like that. If you initialise everything in one 'On start of layout' trigger, then you have clear control on the order things happen.

  • Well now you have two 'On start of layout' triggers, one which sets the variable, and another that gets it. It works if it does set then get, but it doesn't work if you get then set. So you've created a dependency on the order on which Construct runs 'On start of layout' triggers. It's best to avoid depending on internal details like that. If you initialise everything in one 'On start of layout' trigger, then you have clear control on the order things happen.

    OK, thanks for the advice. I'll need to store the level variables in a different way, then, since we can't know for sure what order Construct will start each sheet it sounds like. I'm just trying to get all the sprite behavior and positioning set before the layout becomes visible, and need those variables updated level by level beforehand. I'll do it a different way. Thanks :)

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