How do I make a game that saves data properly?

Get help using Construct 2

Post » Sun Feb 01, 2015 12:18 pm

I mean, i have built a game that counts the number of totalkills that the player has made. I decided to use the web storage (as most of scirra's tutorials suggest) to input a number string as a local value so that when the player starts the game, the web storage updates the variable totalkills to the local value saved before. However, instead of saving the value, the project keeps telling me that the totalkills value is: NaN. i don't know what does this mean and i don't know how to fix it.
Thanks. :-)
B
4
Posts: 17
Reputation: 259

Post » Mon Feb 02, 2015 3:18 am

hello, I think you set a string (text) on a number based variable. NaN = Not a Number.

you should save your variable via "set local value" action. fill the Key with your desired save name, and value with your global variable.
to load it, use system -> set value -> WebStorage.LocalValue("save name").
.
I hope you get it, my english isn't very good.
"If you want to move a mountain tomorrow, you should start by lifting stones today."
B
64
S
14
G
3
Posts: 292
Reputation: 7,188

Post » Mon Feb 02, 2015 4:29 am

You need to save totalkills to webstorage each time its updated in your game. And call it once on start of layout to set totalkills to webstorage value.
B
33
S
8
G
2
Posts: 100
Reputation: 2,635

Post » Wed Feb 04, 2015 7:20 pm

That is excatly what i did puntodamar, and i dont think i set a text instead of a number value. And my game set totalkiss value to webstorage value eveytime it is updated in the game thatserafimkid, so i don't know how to work this problem out :(
B
4
Posts: 17
Reputation: 259

Post » Wed Feb 04, 2015 8:14 pm

Make sure you're setting the local key to totalkills (the variable name) and not "totalkills" (a string).
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,680

Post » Thu Feb 05, 2015 10:23 am

And how can i verify if i have set it to the variable and not to a string?
B
4
Posts: 17
Reputation: 259

Post » Thu Feb 05, 2015 10:35 am

It should look like this:
webstorage1.PNG


And not this:
webstorage2.PNG



Also in Chrome you can view the value saved in local storage:
Open the Dev tools (F12). Select resources from the top bar and then click Local Storage on the left. See if you have the correct value stored there.

webstorage3.PNG
You do not have the required permissions to view the files attached to this post.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,680


Return to How do I....?

Who is online

Users browsing this forum: Bing [Bot] and 25 guests