Save a variable even when I close and reopen the game

0 favourites
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • hi guys,

    In the game I'm working on, is available the "time attack mode", but this should only be available when the game has been completed in story mode. So, Looking around, it seems to me that I should use the "local storage" plugin.

    But it seems to me a little complicated and I would not want to do something complex when, in the specific case of what I would do, it might be a simple thing. I would like to thank those who want to help me with that. What I would like to do is type a variable that is saved when completing the game by killing the boss and then recalling it in the main menu even if it closes and relaunches the game to make the time attack mode available or not.

    sorry for my english translation

  • It's not complicated, just follow this tutorial. There's a capx. https://www.scirra.com/tutorials/1461/h ... age-plugin

  • It's not complicated, just follow this tutorial. There's a capx. https://www.scirra.com/tutorials/1461/h ... age-plugin

    hi my friend, one question, this working for "instance variables" values too or only for global variables??

  • It works for Instance Variables yes. At startup you always have to recover the local storage data and store it somewhere in your game : you can store it in an instance variable just as in a global variable

  • If you're referring to a lot of objects each with their own unique instance variables then it is better to go for the save state method, which simply saves the state of the game at that point and the values of all objects.

    https://www.scirra.com/tutorials/526/ho ... -savegames

  • It works for Instance Variables yes. At startup you always have to recover the local storage data and store it somewhere in your game : you can store it in an instance variable just as in a global variable <img src="{SMILIES_PATH}/icon_e_wink.gif" alt=";)" title="Wink">

    thanks Semoreh!!

    If you're referring to a lot of objects each with their own unique instance variables then it is better to go for the save state method, which simply saves the state of the game at that point and the values of all objects.

    https://www.scirra.com/tutorials/526/ho ... -savegames

    this is very quicky option!! but work even if i close and re open the game???

    EDIT: i have just tryed exporting and playng the game and... not work when i close and re open the game the variable value was lost..

  • What did you try?

  • What did you try?

    Save/load state, store temporally the value, when i close and reopen the game valuedata is lost

  • What did you try?

    strange thing is that the page you linked me tell this :"Savegames are stored on disk by the browser. This means players can switch off their computer or device, come back the next day, and the savegame can still be successfully loaded. "

    what im wrong???

  • You save the state of the game. You then exit, re-enter and load the save state, it loads it at the time when you saved it with the same variables and objects. It is like taking a screenshot of the game at the point where you saved it.

  • You save the state of the game. You then exit, re-enter and load the save state, it loads it at the time when you saved it with the same variables and objects. It is like taking a screenshot of the game at the point where you saved it.

    i have ONLY one instance variable that is value 0 from default, when Player beat the final boss, an event set that instance variable value to 1, then ending video, then go to MENU (i put those events on menu sheet of the game, on start of layout -> save state slot action, on an event below, on saving slote complete -> load state), on the menu if the instance variable is 1 the time attack mode is available, otherwise not.

    So practically if i complete the game, when returns to the menu the time attack mode will be available and unlocked and the isntance variable from then on should always be saved as 1.

    what im wrong??

  • You need to use a global variable and local storage for that.

  • You need to use a global variable and local storage for that.

    ok, so the problem is with the instance variable?? o save/load state that isn't possible in my case?? forgiveme but.. i still do not understand .. if I use a global variable, how can I safeguard it? because in game i reset global variables many times..

  • You can safeguard it by not resetting global variables many times. If you want to store variables FOREVER as a mechanism for when something is unlocked by a user then I don't see how resetting them can be good practice. In this case I would reset individual global variables that need to be reset, if they have to be. You could probably reset global variables then load all the keys from local storage but I've not tried this around a reset.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can safeguard it by not resetting global variables many times. If you want to store variables FOREVER as a mechanism for when something is unlocked by a user then I don't see how resetting them can be good practice. In this case I would reset individual global variables that need to be reset, if they have to be.

    wait a moment, before reviewing half project to reset variables one by one with the risk of forgetting something or making mistakes, if save/load state make a gameshot of the situation (global and instance variable included) and if store permanently this "state" of the game as said "Savegames are stored on disk by the browser. This means players can switch off their computer or device, come back the next day, and the savegame can still be successfully loaded. " in the page you linked me https://www.scirra.com/tutorials/526/ho ... -savegames

    so, what the problem with mi situation? why don't work? because save state plugin save and load state of all variables, instenace included.

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