How to Save and Load a number value very easy !!

1

Stats

4,453 visits, 6,095 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 12 May, 2015. Last updated 19 Feb, 2019

Hi guys,

Here is the simplest way to Save and Load a score value

(you can do it for any other number value).

First, insert a WebStorage object. (don't worry, it will not save it on the web)

Then, insert a SpriteFont objet and call it "MyScore"

Then, insert a keyboard object if you don't have already it.

(we will use it to add and substract to the score to test it)

Now let's begin the Event Sheet.

go to the event sheet and add a new global variable and call it "VScore"

(to do it, "left clic and select add a new global variable")

Then, add the following events :

the first event is to display the value of the global variable VScore.

With these, if you launch the game, you'll be able to see the score on the screen,

and add 1 by pushing up key, and substract 1 by pushing down key.

OK, finally, Save and Load system :D

just add these 2 events :

the LOAD event :

insert a new condition : keyboard : on key pressed : select S key,

then add an action : WebStorage : Set local value,

it will ask you a key and a value, imput these :

notice that the Key is behind "quotes" and the value is not. (the value is the name of your global variable VScore)

and now,

the SAVE event :

insert a new condition : keyboard : on key pressed : select L key,

then add an action : System : Global an local variables, Set Value,

on the opening window select your global value VScore, and add this :

normally you'll have this :

just be very carefull about the quotation marks, as it is written, if you imput on the wrong place it will not work !!

we're done normally you can now save and load your score value by pushing S and L.

just a supplement tip if you want it,

to put your score at screen on the right place :D

you can change the start position (and so the others) just remember that's always 16 pixel on each different position with the normal SpriteFont object.

Thank you for reading hope this tuto has been usefull !!

  • 0 Comments

Want to leave a comment? Login or Register an account!