How do I use variables and layouts?

0 favourites
  • 8 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • i have for example a global number called box with the value 1 declared in layout1.

    If i set the box variable with the value 2, i can set to 2 and use a webstorage as set local key to "2".

    Then i change to the layout 2 and on start of layout 2 i set box to webstorage.localvalue("2").

    The thing is when i change to layout1 i need to also set the variable box to webstorage.localvalue("2") to load it because when i change to layout 1 is declared as 1.

    The question is... i need to load the variable in every layout all the time?

    hope y can explain the question.

  • let me reformulate the question:

    if i have a global variable and change the value i need to load with webstorage in every layout?

  • global variables keep their values when changing layouts, only closing the game, use the reset global variables action or setting them yourself will change their values.

  • This means if i change the value of the variable i need save it in webstorage and then need to webstorage load in every layout right?

  • You only need to save the global variable if you are going to quit the game and restart..

    Global means that it is accessable from every layout, so when you set it in layout one, what you set will be available in layout two..

    If however you quit the game this info is lost..

    No need to save to webstorage unless you reload the entire game..

  • If im correct if i have a variable with the value 1 and change it to the value 2 and change the layer the variable is automatically set to 1 again.... mmmmm... now i think why... is because on start of the second layout all the variables are reseted....

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • katzin, hi...

    If the global variable (GV) is resetting to the default value between layouts, then you must be telling it to do so somewhere in your code.

    GV's are accessible at any time from any layout. So if GV is set to 1 in layout1, it will still be 1 when you go to layout2. Make sure you are not resetting it when the layout starts.

    Can you provide simple capx...

  • I found what is the problem:

    Im taking one of the templates that when the start of layout all the variables are reseted.

    This means in layout 1 i change the variable and when i changed to layer 2 is changed to the original value because of the "on start of layout reset all the variables".

    So the solution for me was in layout 1 save the value with webstorage and in layout 2 after the reset load the value saved before.

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