Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How do you make something Save/Load?
- TMF10
-
Scratcher
100+ posts
How do you make something Save/Load?
Hi.
I'm making a particularly big game, and I want to make it so that players can get their gold back by using a Save and Load button.
Basically, player earns gold, player saves amount of gold they have, they get on the game later, load their gold, and get back the amount of gold they had.
But I have no idea how the heck to use cloud lists and cloud variables, and I'd like some help on coding it.
Can I have some help?
I'm making a particularly big game, and I want to make it so that players can get their gold back by using a Save and Load button.
Basically, player earns gold, player saves amount of gold they have, they get on the game later, load their gold, and get back the amount of gold they had.
But I have no idea how the heck to use cloud lists and cloud variables, and I'd like some help on coding it.
Can I have some help?
- 280870
-
Scratcher
72 posts
How do you make something Save/Load?
I can help maybe.
So, there are two ways to do this:
Option 1
Trust your players to truthfully remember the exact amount of money they had.
To do this
Go on the backdrop code

Do:
This is if you don't trust players. This system uses letters and symbols. I'm making a project with this so ill add the link later.
So, there are two ways to do this:
Option 1
Trust your players to truthfully remember the exact amount of money they had.
To do this
Go on the backdrop code

Do:
ask [If you played before, how much money did you have? If you are new type (put the starter amount here)] and waitOption 2
set [money] to (answer)
This is if you don't trust players. This system uses letters and symbols. I'm making a project with this so ill add the link later.
- Abcpunit
-
Scratcher
87 posts
How do you make something Save/Load?
If someone is making a game with more than one variable to store, then I would suggest using save codes (and yes I have used them before)
Lets start with saving
So first:
And after that:
The final result should look like this:
Then to load you would do this:
And there you go!
Have a nice day!
Lets start with saving
So first:
(join (Variable 1) (Variable 2)and so on.
And after that:
set [Save code v] to (join (Variable 1) (Variable 2))
The final result should look like this:
when green flag clicked
forever
if <<touching [Mouse pointer v] ?> and <mouse down?>> then
show variable [Save code v]
set [Save code v] to (join (Variable 1) (Variable 2))
else
hide variable [Save code v]
end
end
Then to load you would do this:
when this sprite clicked
ask [What is your code? (or something like that)] and wait
set [Variable 1 v] to (letter (1) of (answer))
set [Variable 2 v] to (letter (2) of (answer))
And there you go!
Have a nice day!
- TMF10
-
Scratcher
100+ posts
How do you make something Save/Load?
*snip*
But what if I was using variables that had more than one digit? Like, 12 of one variable but it starts at zero and 800 of one variable but still started at zero?
- LPopandron
-
Scratcher
4 posts
How do you make something Save/Load?
*snip*
But what if I was using variables that had more than one digit? Like, 12 of one variable but it starts at zero and 800 of one variable but still started at zero?
Hi there!
Your ‘code’ has to be the same length everytime. Which means that there should be some sort of maximum value for a variable there.
Let's fix this limit to 100. You'd need a way to convert any value between 0 and 100 to some code that has a constant length. Turns out, it is very easy! You can just do a simple addition and it will always work.
Example:
set [code v] to ((money) + (100)) // You can try this, it will always have a length of 5, for 'money' is set between 0 and 100.And you can just repeat this process for every variable you want, to finally join them all using the ‘join’ block:
(join ((money) + (100)) ((money2) + (100))) // And of course, 'money' and 'money2' are both between 0 and 100.
You can repeat this as long as you want; although your code might be somewhat long at some point.
Getting the values back is pretty straight forward:
set [money v] to ((join (join (letter (1) of (code)) (letter (2) of (code))) (letter (3) of (code))) - (100)) // Undo addition from above.
set [money2 v] to ((join (join (letter (4) of (code)) (letter (5) of (code))) (letter (6) of (code))) - (100)) // same here!
- You have to always make sure that your ‘money’ variable, no matter how high it goes, has the same length when doing the addition. This is fairly easy

Have a good day !
- Navull
-
Scratcher
12 posts
How do you make something Save/Load?
Well, you can just have the Players Export/Import a List holding all the values.
If you want to make it somewhat anti-cheat, you can encode the list before having the Player export it.
Then decode the list when importing.
Here's a little example (without Encoding/Decoding);
I recommend checking this out if you are interested in encrypting Data;
https://en.scratch-wiki.info/wiki/Encryption
If you want to make it somewhat anti-cheat, you can encode the list before having the Player export it.
Then decode the list when importing.
Here's a little example (without Encoding/Decoding);
when I receive [ Save]If you want to encode your list, do it before you show the list. And decode it before setting the values.
delete (all) of [Save List]
add (Gold) to [Save List]
show list [ Save List]
ask [Press Enter when exported List] and wait
hide list [ Save List]
when I receive [ Load]
delete (all) of [Save List]
show list [ Save List]
ask [Press Enter when imported List] and wait
set [ Gold] to (item ( 1) of [Save List] :: list)
I recommend checking this out if you are interested in encrypting Data;
https://en.scratch-wiki.info/wiki/Encryption
- RokCoder
-
Scratcher
1000+ posts
How do you make something Save/Load?
You can use my save game toolkit. It doesn't do all the work for you but it certainly does most of it. You'd need to read the instructions to be able to use it (which are in a forum linked from the notes and credits of the project).
It allows you to save integers, floats, booleans, strings and lists (so pretty much anything you'd want to be able to save). It requires you to copy your data in to a list and call a SaveData broadcast to get the save code. To load from the save code you need to broadcast LoadData and then copy from the list back into your variables.
You also have to set up a simple script so the toolkit knows what data to expect at each entry in the list. For example -
integer min 4 max 67
integer min -255 max 255 array 200
boolean array 20
The above would expect the first entry to be an integer between 4 and 67. It would then expect the next 200 entries to be integers between -255 and +255 (most likely from a list) and then it would expect the next 20 entries to be booleans (true/false). It sounds more complicated than it is but that's so that it can be flexible and usable for pretty much any case.
It allows you to save integers, floats, booleans, strings and lists (so pretty much anything you'd want to be able to save). It requires you to copy your data in to a list and call a SaveData broadcast to get the save code. To load from the save code you need to broadcast LoadData and then copy from the list back into your variables.
You also have to set up a simple script so the toolkit knows what data to expect at each entry in the list. For example -
integer min 4 max 67
integer min -255 max 255 array 200
boolean array 20
The above would expect the first entry to be an integer between 4 and 67. It would then expect the next 200 entries to be integers between -255 and +255 (most likely from a list) and then it would expect the next 20 entries to be booleans (true/false). It sounds more complicated than it is but that's so that it can be flexible and usable for pretty much any case.
- loveteaching
-
Scratcher
62 posts
How do you make something Save/Load?
Most games use a coder and decoder to make the save code.
- RokCoder
-
Scratcher
1000+ posts
How do you make something Save/Load?
Most games use a coder and decoder to make the save code.Which is what you'll find in the post before yours. Ready to be put into a backpack and added to any project

- Jogos_Em_3D
-
Scratcher
24 posts
How do you make something Save/Load?
people here on the replys doesnt even help people
they just say “JuSt MaKe A bLoCk ThAt SaVeS”
they just say “JuSt MaKe A bLoCk ThAt SaVeS”
- Enigma_Ezra
-
Scratcher
500+ posts
How do you make something Save/Load?
Use this link: https://scratch.mit.edu/projects/558506215/
- MatsuoBasho
-
Scratcher
1 post
How do you make something Save/Load?
Hi. Im making a game where a sprite shoots a fireball, but the code only works when you are touching the powerup. How do I make it so that the palyer can shoot maybe 3 fireball, while only touching the powerup once?
- colinpenguin
-
Scratcher
100+ posts
How do you make something Save/Load?
Hi. Im making a game where a sprite shoots a fireball, but the code only works when you are touching the powerup. How do I make it so that the palyer can shoot maybe 3 fireball, while only touching the powerup once?Please do not necropost (post on a old topic).
- bacon_cheese_burger
-
Scratcher
5 posts
How do you make something Save/Load?
I need a save load for a 3d game kinda like Minecraft
and i need to know where they have there blocks
and i need to know where they have there blocks
Last edited by bacon_cheese_burger (May 9, 2024 22:13:43)
- Discussion Forums
- » Help with Scripts
-
» How do you make something Save/Load?













