Discuss Scratch

MARIOGUY_1
Scratcher
21 posts

how can you make save codes for your projects? -MARIOGUY_1

i really need this
supa-panda
Scratcher
100+ posts

how can you make save codes for your projects? -MARIOGUY_1

It really depends on you project sometimes it might be a simple as
(join (join (player x) (-)) (player y))
But for a more complicated game (say something like a 2d editable world) save codes could be far more complicated. What kind of save code do you need?

Sorry if that sounds like a cheesy advertisement
Anuhmayshun
Scratcher
100+ posts

how can you make save codes for your projects? -MARIOGUY_1

This might help. It's a great tutorial and teaches the basics of save codes. Of course, save codes mean that people could abuse the system to cheat.
Spentine
Scratcher
1000+ posts

how can you make save codes for your projects? -MARIOGUY_1

Use this script if you're fine with the player modifying the variables:
define encode
set [save code v] to ()
set [index v] to (0)
repeat (length of [list v])
change [index v] by (1)
set [char index v] to (0)
repeat (length of (item (index) of [list v]))
change [char index v] by (1)
if <[/,] contains (letter (char index) of (item (index) of [list v]))? :: operators> then
set [save code v] to (join (savecode) [/]
end
set [save code v] to (join (save code) (letter (char index) of (item (index) of [list v])))
end
set [save code v] to (join (save code) [,])
end

define decode (string)
delete [all v] of [list v]
set [char index v] to ()
set [index v] to (1)
repeat until <(index) > (length of (string))>
if <(letter (index) of (string)) = [,]> then
add (char index) to [list v]
set [char index v] to ()
else
if <(letter (index) of (string)) = [/]> then
change [index v] by (1)
end
set [char index v] to (join (char index) (letter (index) of (string)))
end
change [index v] by (1)
end

How to use:
Add all the variables you want to save into the list list. Then, run the encode script to encode the list into a savecode. When loading a savecode, run the decode script to decode the savecode into a list, and then set each variable to its item in the list.

If you're creating a clicker game and you don't want anybody to modify the values, you can alternatively use this:
define hash(str
set[output v]to(77978
repeat(length of(str
set[output v]to(((([floor v]of((output)/(77977)))+(1))*(77977))+((((output)mod(77977))*(([e ^ v]of((<[qetuoadgjlxvn13579`!#%&\(-_\[\\};:,/>]contains(letter([floor v]of((output)/(77977)))of(str))?>+((2)*(<[weyupafgklcvm14589~!$%*\(=_\]\\|;",\<\>]contains(letter([floor v]of((output)/(77977)))of(str))?>+((2)*(<[rtyusdfgzxcv23450`~!^&*\(+\[\]\\':",?]contains(letter([floor v]of((output)/(77977)))of(str))?>+((2)*(<[iopasdfgbnm12345@#$%^&*\({}|;':",]contains(letter([floor v]of((output)/(77977)))of(str))?>+((2)*(<[hjklzxcvbnm12345\)-=_+\[\]\\{}|;':",]contains(letter([floor v]of((output)/(77977)))of(str))?>+((2)*(<[67890`~!@#$%^&*\(\)-=_+\[\]\\{}|;':",]contains(letter([floor v]of((output)/(77977)))of(str))?>+((2)*<[./\<\>?]contains(letter([floor v]of((output)/(77977)))of(str))?>))))))))))))/(3)))*(2.71)))mod(77977
end
set[output v]to((output)mod(77977

define encode
set [save code v] to ()
set [index v] to (0)
repeat (length of [list v])
change [index v] by (1)
set [char index v] to (0)
repeat (length of (item (index) of [list v]))
change [char index v] by (1)
if <[/,] contains (letter (char index) of (item (index) of [list v]))? :: operators> then
set [save code v] to (join (savecode) [/]
end
set [save code v] to (join (save code) (letter (char index) of (item (index) of [list v])))
end
set [save code v] to (join (save code) [,])
end

define decode (string)
delete [all v] of [list v]
set [char index v] to ()
set [index v] to (1)
repeat until <(index) > (length of (string))>
if <(letter (index) of (string)) = [,]> then
add (char index) to [list v]
set [char index v] to ()
else
if <(letter (index) of (string)) = [/]> then
change [index v] by (1)
end
set [char index v] to (join (char index) (letter (index) of (string)))
end
change [index v] by (1)
end

define encode savecode
encode
hash (savecode)
set [savecode v] to (join (savecode) (join (output) [,]))

define decode savecode (savecode)
decode (savecode)
set [previous hash v] to (item [last] of [list v])
delete [last] of [list v]
encode
hash (savecode)
if <(output) = (previous hash)> then
The savecode is valid and not modified :: grey
else
The user modified the savecode :: grey
end

How to use:

When encoding a savecode, add the variables you want to save to the list list, and then use the encode savecode list. After a savecode is decoded, its contents will be dumped into the list and you could set each variable to its respective item index. Since there is modification protection (although basic, still works), you can detect if the user modified the savecode. You could also encode the username into the savecode to have it only be for one user.
MARIOGUY_1
Scratcher
21 posts

how can you make save codes for your projects? -MARIOGUY_1

wow! that looks very difficult!
legendary34678
Scratcher
1000+ posts

how can you make save codes for your projects? -MARIOGUY_1

Normally you would just use a simple encoding and decoding system rather than Spentine's monstrous hash custom block.
Spentine
Scratcher
1000+ posts

how can you make save codes for your projects? -MARIOGUY_1

legendary34678 wrote:

Normally you would just use a simple encoding and decoding system rather than Spentine's monstrous hash custom block.
guess what my custom bloc is good and works and that's all that matters hehehehehehe
RareCybop135
Scratcher
2 posts

how can you make save codes for your projects? -MARIOGUY_1

Do you have any methods for Pokemon-like games? I'm making a game called ALBT and I want people to save items and currency and stuff.
Elijah999999
Scratcher
1000+ posts

how can you make save codes for your projects? -MARIOGUY_1

Well, I suggest you create a string that has all the vital information stored within it (as letters and numbers and such.) Then the project can be programmed to set the variables and lists to whatever the string calls for.
Spentine
Scratcher
1000+ posts

how can you make save codes for your projects? -MARIOGUY_1

RareCybop135 wrote:

Do you have any methods for Pokemon-like games? I'm making a game called ALBT and I want people to save items and currency and stuff.
use my thing and encode the stuff ez
MARIOGUY_1
Scratcher
21 posts

how can you make save codes for your projects? -MARIOGUY_1

Mabey a simple script please! ADVANCED SCRIPT

Powered by DjangoBB