ID:2086547
 
(See the best response by Ter13.)
Code:
mob/proc/test(){for(var/a in vars){world.log << "[a];[vars[a]]"}}


Problem description:

The vars list var is probably one of the most useful vars when dealing with saving and the like. I was wondering if there was some way you could do the same thing for the world node, whereas you'd have access to global variables.

Example:
proc/test(){for(var/a in vars){world.log << "[a];[vars[a]]"}}


Any ideas??
What I do is set up a datum containing all the world vars I want to be able to edit or save.

That way I also never have to ever write new code for saving/loading when I add new world vars.

var/worldVars/worldVars

worldVars
var
thisSaves
tmp
thisDoesNot

...
var/savefile/s = new ("world.sav")
s["worldVars"] >> worldVars

s["worldVars"] << worldVars
Best response
The vars list var is probably one of the most useful vars when dealing with saving and the like. I was wondering if there was some way you could do the same thing for the world node, whereas you'd have access to global variables.

You should never have to deal with the vars list during saving.

Saving should be as simple as savefile << mob

Provided you've actually marked variables as temporary when you were supposed to, you should never have to muck with atom.vars during reading/writing. For any variables that you need to modify during saving, you'll want to handle it in a read/write override while marking the original as temporary.

I do this for time offsets:

mob
var/tmp
stun = 0
Move()
if(stun>world.time) return 0
return ..()

Write(savefile/F)
..()
F["stun"] << max(stun-world.time,0)

Read(savefile/F)
..()
F["stun"] >> stun
stun += world.time


For any globals that I need to deal with, I typically define a datum to handle it, so I can dump the datum to a savefile:

var
global_properties/global_properties = new()

global_properties
var
someproperty = 4


Now you can dump the global_properties datum to a savefile and load it on world start. A little more overhead than a global, but a lot easier to work with for saving/restoring data between sessions.
Tiny note, if you're going to save/load the datum, don't bother doing new() on the var since loading should handle that.
Thanks. I just wondered if there was a way to do it without categorizing all global variables to a lower level, but any of this works just as well if I'm not so lazy.
Unfortunately there is no world.vars support for global vars. There's nothing setup in the compiler to keep track of them in this way, and the means to change that are deep in the axial deframbulator.
In response to Lummox JR
Lummox JR wrote:
axial deframbulator.




Third time's a charm!