Discuss Scratch

Mr-PepperoniMan
Scratcher
10 posts

How do I make multi digit save codes on scratch

I am making a cookie clicker based game and I need to have a save code that uses multiple digits for some variables. Basically I need a save code that can support things like: 294 currency, 21 buildings, 8 currency per second.
DABdavid
Scratcher
29 posts

How do I make multi digit save codes on scratch

define save
set [final v] to (join (length of (currency)) (currency))
set [final v] to (join (final) (join (length of (currency per second)) (currency per second)))
set [final v] to (join (final) (length of (length of [buildings v] :: list)))
set [final v] to (join (final) (length of [buildings v] :: list))
set [idx v] to [1]
repeat (length of [buildings v] :: list)
set [final v] to (join (final) (length of (item (idx) of [buildings v] :: list)))
set [final v] to (join (final) (item (idx) of [buildings v] :: list))
change [idx v] by (1)
end
Use this. Buildings will be a list, where the elements in the list are the number of owned buildings for each building type. The currency and currency per second will both be numbers. Make sure to create a variable named “final” for this. The “final” variable will be set to the save code after running this save script.
Ranger_07
Scratcher
100+ posts

How do I make multi digit save codes on scratch

DABdavid wrote:

define save
set [final v] to (join (length of (currency)) (currency))
set [final v] to (join (final) (join (length of (currency per second)) (currency per second)))
set [final v] to (join (final) (length of (length of [buildings v] :: list)))
set [final v] to (join (final) (length of [buildings v] :: list))
set [idx v] to [1]
repeat (length of [buildings v] :: list)
set [final v] to (join (final) (length of (item (idx) of [buildings v] :: list)))
set [final v] to (join (final) (item (idx) of [buildings v] :: list))
change [idx v] by (1)
end
Use this. Buildings will be a list, where the elements in the list are the number of owned buildings for each building type. The currency and currency per second will both be numbers. Make sure to create a variable named “final” for this. The “final” variable will be set to the save code after running this save script.
Ima say the loading script would work like this:
define LOAD (save code)
// make sure you check "run without screen refresh"
set [final v] to (save code)
set [idx v] to (1)
read value
set [currency v] to (value)
read value
set [currency per second v] to (value)
delete all of [buildings v]
read value
repeat (value)
read value
add (value) to [buidings v]
end

define read value
// make sure you check "run without screen refresh"
set [value v] to ()
repeat (letter (idx) of (final))
change [idx v] by (1)
set [value v] to (join (value) (letter (idx) of (final)))
end
change [idx v] by (1)

Last edited by Ranger_07 (May 11, 2024 03:14:38)

Mr-PepperoniMan
Scratcher
10 posts

How do I make multi digit save codes on scratch

Thank you.

Powered by DjangoBB