Save a variable even when I close and reopen the game

Get help using Construct 2

Post » Thu Jul 20, 2017 10:29 am

plinkie wrote: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??
B
12
S
6
G
3
Posts: 278
Reputation: 3,239

Post » Thu Jul 20, 2017 10:35 am

You need to use a global variable and local storage for that.
B
46
S
16
G
77
Posts: 2,159
Reputation: 45,833

Post » Thu Jul 20, 2017 11:08 am

plinkie wrote: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..
B
12
S
6
G
3
Posts: 278
Reputation: 3,239

Post » Thu Jul 20, 2017 11:14 am

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.
B
46
S
16
G
77
Posts: 2,159
Reputation: 45,833

Post » Thu Jul 20, 2017 11:27 am

plinkie wrote: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.
B
12
S
6
G
3
Posts: 278
Reputation: 3,239

Post » Thu Jul 20, 2017 11:54 am

The problem is that you said you wanted a way of saving instance variables and I recommended that link. What you should be doing is saving that unlock information as a global variable, local storage is what you should be using for this. If it's not working properly with other global variables then it's a logic error, possibly you are loading the key items to global variables then resetting their values afterwards.
B
46
S
16
G
77
Posts: 2,159
Reputation: 45,833

Post » Thu Jul 20, 2017 12:01 pm

plinkie wrote:The problem is that you said you wanted a way of saving instance variables and I recommended that link. What you should be doing is saving that unlock information as a global variable, local storage is what you should be using for this. If it's not working properly with other global variables then it's a logic error, possibly you are loading the key items to global variables then resetting their values afterwards.

May it be a problem related to this ??
"Note that most browsers have a limit on how much data a web page can save to disk.... Appropriate use of the No Save behavior can also help make savegames smaller (see below)."
in fact, even if I export game to nw.js is still based on the chromium browser right?
in my project I did not use "No Save behavior" on objects and the project capx is 130MBytes, (90MB of videos)..
B
12
S
6
G
3
Posts: 278
Reputation: 3,239

Post » Thu Jul 20, 2017 12:07 pm

No idea about that but you don't need to use that save state now that you've explained what you're trying to save. To check whether time attack mode is available you just need local storage and a key. To toggle whether it is available use a global variable instead of an instance variable.
B
46
S
16
G
77
Posts: 2,159
Reputation: 45,833

Post » Thu Jul 20, 2017 1:58 pm

plinkie wrote:No idea about that but you don't need to use that save state now that you've explained what you're trying to save. To check whether time attack mode is available you just need local storage and a key. To toggle whether it is available use a global variable instead of an instance variable.


ok done it, now is working fine.
anyway nonsense problem with reset global variables one by one to avoid "reset global variable" because "reset global variable" fortunately DON'T touch key stored values ;)
So I could safely enter key value e reload them at the appropriate moment
B
12
S
6
G
3
Posts: 278
Reputation: 3,239

Previous

Return to How do I....?

Who is online

Users browsing this forum: ST314, tarek2, Yahoo [Bot] and 23 guests