ID:149437
 
This is my first forray into savefiles. I need to save and load world globals. Also a quick question. Can lists be saved?
This code here does not seem to work correctly and I am not positive how to make a savefile correctly.
var
global
currentcycle = 0
gametime = 0 //running clock
timeinterval = 10 //How long until a gametime tick in 1/10 of a second?
nextperiod //When is the next period of darkness?
lastperiod //When was the beginning of this period?
cycleperiod = 120 //How long does a period last?
world
area = /area/outside
turf = /turf/grass
view = 5
New()
..()
var/savefile/worldsave = new("globals.sav")
worldsave["cycle"] >> currentcycle
worldsave["time"] >> gametime
worldsave["nperiod"] >> nextperiod
worldsave["lperiod"] >> lastperiod
Del()
world << "Saving global variables..."
var/savefile/worldsave = new("globals.sav")
worldsave["cycle"] << currentcycle
worldsave["time"] << gametime
worldsave["nperiod"] << nextperiod
worldsave["lperiod"] << lastperiod
world << "Global Variables have been saved."
I believe this would work for saving lists, note: just an example.

var/list/bah

world/New()
..()
var/savefile/F = new("bah.sav")
F["bah"] >> bah
if(isnull(bah))
bah = new /list
world/Del()
var/savefile/F = new("bah.sav")
F["bah"] << bah
..()

That should work post if it doesn't :)

Also one thing I believe what you put should have worked.. Did you get errors and are you sure they aren't saving and loading?