< User:AonymousGuy

Simple Tutorial

This tutorial will go over making a simple save system which stores values in a list.

Storing Data

All the data will be stored in a single string which will be put back into the project at a later date to load the old data the player had.

To start, make a list called "Save Data". Next, make the following custom block which will save data:

define save (value)
add (join (value) [;]) to [Save Data v]

You can then make a script to save any variables you want:

save (x position) //category=custom
save (health) //category=custom
save (money) //category=custom

Giving the code to the user

The next step is to give the save code to the user so they can enter it in later. You can do so like this:

set [code v] to [] //Make sure there is nothing inside the second input
repeat until <(length of [Save Data v]) = [0]>
set [code v] to (join (code) (item (1 v) of [Save Data v]))
delete (1 v) of [Save Data v]
end
add [code v] to [Save Data v]
show list [Save Data v]

The user can then export the list or copy and paste the code somewhere.

Loading Data

Finally, the user needs to be able to load data. Make a list called "Loaded Data", then make the following custom block:

define load data (data)
set [i v] to [1]
set [value v] to [] //Make sure the second input is blank
repeat until <(i) > (length of (data))>
repeat until <(letter (i) of (data)) = [;]>
set [value v] to (join (value) (letter (i) of (data)))
change [i v] by (1)
end
add (value) to [Loaded Data v]
change [i v] by (1)
set [value v] to [] //Make sure the second input is blank
end

Now you simply need to load the data in the order that you saved it. You first ask the player for their save code, then load the data, and then store the loaded data. So for the above example where "x position" is stored, then "health", then "money". The loading script would look like this:

ask [Save code?] and wait
load data (answer) //category=custom
set x to (item (1 v) of [Loaded Data v])
set [health v] to (item (2 v) of [Loaded Data v])
set [money v] to (item (3 v) of [Loaded Data v])