How do I reset global variables but only for current event sheet?

0 favourites
  • 12 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hi,

    I want to reset global variables,but only for "current event sheet". I don't want to reset global variables for whole game

    How can I do this? I am even ready to go for script way

    Thanks in advance

    Ashley Is it even possible?

  • This is not possible. You will have to reset each variable one by one with "System Set variable" actions.

  • the problem is, global variables are actually "global". There are none that are scoped to just that sheet/layout. Global vars can be made anywhere in the project, what sheet they are declared on is arbitrary. what you are describing is a local variable.

    if you want those variables to be confined to just that event sheet, place all the events inside of a group, then drag all the variables to be at the top of the group. then each of the variables will be reinitialized each time you run the layout.

  • jobel Variables placed inside a group will become local. Local variables are reset on every tick, unless they are set as static. And there is no easy way to reset all static local variables. So OP will still have to reinitialize each such variable individually on start of the layout.

  • dop2000

    construct.net/en/forum/construct-3/general-discussion-7/changing-global-variable-160210

    I haven't actually tried it myself... I only use globals and locals that are only temporary.

  • Local static variables are similar to global, but you can't reset them all with one action.

    If you need lots and lots of variables, you can use a global object (invisible sprite) to store them. This way if you need to reset them, you can destroy and recreate the sprite.

    You can have several of such "dummy" objects, for example one to store variables related to game settings, another to store game statistics/scores etc.

    Or use dictionaries.

  • Isn't there some way through scripting that I can accomplish this?

    For example:- Code will detect the variables declared in the current event sheet and reset only them

    Anyway, super thanks for trying to help me. I think that I should apply for new feature

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Code will detect the variables declared in the current event sheet and reset only them

    No, this is not possible, because global variables are not really assigned to event sheets.

    Maybe if you add a specific prefix to a group of variables (for example EnemySpeed, EnemyDamage), you will be able to loop through all variables with this Enemy* prefix in a script. But still I don't think it's possible to get their default values to reset them to.

  • > Code will detect the variables declared in the current event sheet and reset only them

    No, this is not possible, because global variables are not really assigned to event sheets.

    Maybe if you add a specific prefix to a group of variables (for example EnemySpeed, EnemyDamage), you will be able to loop through all variables with this Enemy* prefix in a script. But still I don't think it's possible to get their default values to reset them to.

    Yes, there is prefix in variables allocated for every different event sheet.

  • I don't know Javascript that well. I think you can do something like runtime.GlobalVars.forEach(....), and compare prefix.

    But like I said, there is no way to get the default value for each variable, so you can only reset them all to 0 or "".

  • Just make a function that sets the values of the global variables you want to change. Don't overcomplicate it!

  • Just make a function that sets the values of the global variables you want to change. Don't overcomplicate it!

    There are more than 200 mini games inside a single game. So...

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