Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Save codes
- Izzy989
-
Scratcher
7 posts
Save codes
I just can't figure out how to make a save code no matter how hard I try! Can somebody please explain it to me then give me an example?
when green flag clicked
if <thirsty> then
say [drink water] for (2) secs
ask [why?] and wait
say [Because you'll die of dehydration, otherwise] for (2) secs
end
- Non-Generic_Cube
-
Scratcher
6 posts
Save codes
Well, I don't think I can explain it, but I made a save code using a tutorial. Just search up ‘save code tutorial ’ on Scratch, hope that will help! 
Also, if you wanna make more complex save codes that are harder to cheat on, search up ‘encoding and decoding’

Also, if you wanna make more complex save codes that are harder to cheat on, search up ‘encoding and decoding’
Last edited by Non-Generic_Cube (Sept. 23, 2024 17:17:37)
- bombardingppl
-
Scratcher
500+ posts
Save codes
A lot of save codes are when you join all of the data sets into a single string and be able to decode it into data again when they load the code. Here's an example.
Clicker game
clicks: 100
clicks per second: 5
The save code would look something like “100 5” or maybe “100|5”. You usually want to avoid the one with the spaces, because some data values might include spaces, let's say something like, “diamond clicker”, and the save code might look like “100 5 diamond clicker”. Now this is a problem because when you decode the code, it might think that there are 4 values instead of three, thinking that the “diamond” and “clicker” are different. So it's a good idea to use a separator that will never appear in your data.
Now let's use the “|” to separate our data. This is what our code might look like
decoding is very difficult and if you'd like I'll show you how that is done if you let me know. For now, this is a way of encoding data.
Clicker game
clicks: 100
clicks per second: 5
The save code would look something like “100 5” or maybe “100|5”. You usually want to avoid the one with the spaces, because some data values might include spaces, let's say something like, “diamond clicker”, and the save code might look like “100 5 diamond clicker”. Now this is a problem because when you decode the code, it might think that there are 4 values instead of three, thinking that the “diamond” and “clicker” are different. So it's a good idea to use a separator that will never appear in your data.
Now let's use the “|” to separate our data. This is what our code might look like
add (clicks) to [save code v]
add (clicks per second) to [save code v]
set [iteration v] to [1] //iteration means the number showing how many times you repeated something
set [save code v] to [] //this is blank, no space.
repeat (length of [save code] :: list)
set [save code v] to (join (save code) (item (iteration) of [save code v] :: list))
change [iteration v] by [1]
end
decoding is very difficult and if you'd like I'll show you how that is done if you let me know. For now, this is a way of encoding data.
- bsteichman
-
Scratcher
500+ posts
Save codes
well first you take any variables that you would need EX) health, playerX, playerY, number of consumables left and simply join them:
set [save code v] to (join (join (join (join (playerx) [|]) (playery)) [|]) (health)) //Output would look something like 200|-50|79then give them the code:
delete all of [copy this! v]::listthen to use this save code, do something like:
add (save code) to [copy this! v]
show list [copy this! v]
when I receive [ask for save code v]
ask [gimmie code] and wait
delete all of [separated v] ::list
set [i v] to [1]
set [split v] to []
repeat (length of (answer))
if <[|] = (letter (i) of (answer))> then
add (split) to [list v]
set [split v] to []
else
set [split v] to (join (split) (letter (i) of (answer)))
end
change [i v] by (1)
end
- Tornadowrath
-
Scratcher
90 posts
Save codes
I've never done this before but I'd imagine it involves assigning a variable to every aspect of your game (EX: lvl/wave, items in inv., etc.) then combining them into a long string of text separated by a certain character (EX: blahblahblahEblahblahblahE…), then you'd probably want to find some method to encrypt and decrypt it (like assigning each character a separate character), after which you should probably show the code on screen (via lists) for the player to copy. When starting your game, you should then have a load option to decrypt the data after they paste it in and then look through each instance of the separating letter and input the following code into corresponding variables. I'm sure there's an easier way but this is the only thing I could think of off the top of my head.
- Discussion Forums
- » Help with Scripts
-
» Save codes