Saving score and scene level

  • I have looked at the save tutorial but I am not sure how to actually get a score to save. How do I let say onuce screen is touched add 5 points that I can then save. Also how do I save the level or sceen they are on to start at the same spot next time they open app?

  • Admin

    So how saving works is you're saving data. You can't save the state or the screen.
    There are 2 tricks with saving and loading.

    1. know what you want to save/load
    2. know when to save/load. This one is the most important, because it can drastically change your results.

    So, say you want to save 5 points when you press a save button.
    You can do something like this:
    Stopped touching --> Save to File
    Then on the save behaviour properties, add a key (this is how you will reference what you saved). So enter something like Score.
    In the next box you enter the score value it self that you want saved. So drag in the points from either a box container, or "get Label" behaviour into this field.

    Now when the user pressing a "save" button it will save.
    In a real world, you probably don't want to have a save button. Instead you would want to save when your character does something. Beats a high score, loses, wins etc.

    Next you would need to load.
    How you want to use that data depends on the load. The flow of loading data usually works like this:

    1. On scene start: Load behaviour
    2. Then output that loaded data into a label or some other useful object.
      Often times with loading errors, users try making use of the data before it's actually loaded.

    So in this example, we will just make a load button.

    Like save, do a stopped touching --> Load from file
    On the load behaviour properties select the Score key.

    Then add something like set label, and connect it to the load. Then output the loaded value to the set label.

    Thats it.

    Here is an example project on saving/loading

    Now for your other question on saving/loading the screen. This is more tricky. And depends heavily on your game. Something like an RPG game, saving/loading is a challenge. You would need to save many things. Characters position, inventory, health, skill etc. All of these would be individual keys/values in the save to file behaviour.
    The when you start the game, load each one and then "set up" the scene with the data.

  • @Murtaza

    For example if I was making a book that has multiple pages and I want the page to be saved to start back at the last page next time the app is opned

  • Admin


    For that what you could do is save the page number each time you turn the page.

    Then when the book first starts load the page number, when user presses resume reading or what ever load scene that matches the loaded value.

Log in to reply