Search code examples
savemit-scratch

How to create a Save/Load function on Scratch?


I am trying to make a game on Scratch that will use a feature to generate a special code, and when that code is input into a certain area it will load the stats that were there when the code was generated. Except I don't know how to make it and I couldn't find a clear answer for how to make it.

I would prefer that the solution be:

  • Able to save information for as long as needed (from 1 second to however long until it's input again.)
  • Doesn't take too many blocks to make, so the project won't take forever to load it.

    Of course, I'm willing to take any solution in order to get my game up and running, those are just preferences.

  • Solution

  • You can put all of the programs in a custom block with "Run without screen refresh" on so that the program runs instantly.

    If you save the stats using variables, you could combine those variable values into one string divided by /s. i.e. join([highscore]) (join("/") (join([kills]) (/))

    NOTE: Don't add any "/" in your stats, you can probably guess why.

    Secret message go BRRR

    Now "bear" (pun) with me, this is going to take a while to read

    Then you need the variables: [read] for reading the inputted code [input] for storing the numbers Then you could make another function that reads the code like so: letter ([read]) of (code) and stores that information to the [input] variable like this: set [input] to (letter ([read]) of (code)). Then change [read] by (1) so the function can read the next character of the code. Once it letter ([read]) of (code) equals "/", this tells the program to set [*stat variable*] to (input) (in our example, this would be [highscore] since it was the first variable we saved) and set [input] to (0), and repeat again until all of the stats variables are filled (In this case, it repeats 2 times because we saved two variables: [highscore] and [kills]).

    2nd secret message, I am silly

    This is the least amount of code that it takes. Jumbling it up takes more code. I will later edit this answer with a screenshot showcasing whatever I just said before, hopefully clearing up the mess of words above.