What is ProgSave? ProgSave works by actually making a program that sets the variables you need. Here's an example
health = 100
score = 0
psave = fs.open("savegame", "w") ;
psave.writeLine("health = "..health.." score = "..score") ;
psave.close()
So as you can see, this actually makes a PROGRAM that sets the variables, hence the name ProgSave.And to load the variables, all you have to do is…
shell.run('savegame') ;
Now here's a more advanced piece of code, one that deletes the save file if it exists before saving to prevent a crash.
health = 100
score = 0
if fs.exists("savegame") == true then
fs.delete("savegame") ;
end
psave = fs.open("savegame", "w") ;
psave.writeLine("health = "..health.." score = "..score") ;
psave.close()
Now, we step it up even more and allow the user to run the save to launch the program, but also launch it within the program
loadingfromgame = true
health = 100
score = 0
if fs.exists("savegame") == true then
fs.delete("savegame") ;
end
psave = fs.open("savegame", "w") ;
psave.writeLine("health = "..health.." score = "..score if loadingfromgame = true then shell.run('game') end ") ;
--note: you cannot use the same string there as the string you used in writeLine.
psave.close()
loadingfromgame = false
Of corse, this doesn't cover tables. That's what this half of the tutorial is about
In this example, we will have a table of an inventory with a stone sword and some dirt.
local inv = {
[1] = "stonesword",
[2] = "dirt",
[3] = "none",
} ;
--now to save this
psave = fs.open("savegame", "w") ;
psave.writeLine("local inv = { [1] "..inv[1]..", [2] "..inv[2].." [3] "..inv[3].." } ;") ;
psave.close()
That's about allTell me if there are any errors or typos in my program.
Also please feel free to ask questions if you don't understand something in this post. You can also PM me.