Save a variable even when I close and reopen the game

Get help using Construct 2

Post » Tue Jul 11, 2017 9:27 pm

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 :)
B
11
S
6
G
2
Posts: 210
Reputation: 2,560

Post » Wed Jul 12, 2017 8:28 am

It's not complicated, just follow this tutorial. There's a capx. https://www.scirra.com/tutorials/1461/h ... age-plugin
B
45
S
15
G
73
Posts: 2,006
Reputation: 43,394

Post » Thu Jul 20, 2017 9:07 am

plinkie wrote: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??
B
11
S
6
G
2
Posts: 210
Reputation: 2,560

Post » Thu Jul 20, 2017 9:12 am

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 ;)
B
5
Posts: 12
Reputation: 258

Post » Thu Jul 20, 2017 9:14 am

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
B
45
S
15
G
73
Posts: 2,006
Reputation: 43,394

Post » Thu Jul 20, 2017 9:23 am

Semoreh wrote: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 ;)

thanks Semoreh!!
plinkie wrote: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..
B
11
S
6
G
2
Posts: 210
Reputation: 2,560

Post » Thu Jul 20, 2017 9:50 am

What did you try?
B
45
S
15
G
73
Posts: 2,006
Reputation: 43,394

Post » Thu Jul 20, 2017 10:06 am

plinkie wrote:What did you try?

Save/load state, store temporally the value, when i close and reopen the game valuedata is lost
B
11
S
6
G
2
Posts: 210
Reputation: 2,560

Post » Thu Jul 20, 2017 10:14 am

plinkie wrote: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???
B
11
S
6
G
2
Posts: 210
Reputation: 2,560

Post » Thu Jul 20, 2017 10:17 am

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.
B
45
S
15
G
73
Posts: 2,006
Reputation: 43,394

Next

Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider], Malhog and 13 guests