ID:263479
 
Code:
proc
SaveTurfs() //This is the Save proc.
var/savefile/F = new ("turfs.sav") //creates the save file
var/list/L = new
for(var/turf/T in world)
T.saved_x = T.x //these tell the game to save the turfs
T.saved_y = T.y //location.
T.saved_z = T.z
L += T
F[""] << L

proc/LoadTurfs() //Its time to load the turfs!
var/savefile/F = new ("turfs.sav")
var/list/L = new
F[""] >> L
if(!L) return
for(var/turf/T in world) if(T.loc) del(T)
for(var/turf/T in L)
T.loc = locate(T.saved_x,T.saved_y,T.saved_z)


Problem description: getting a error on the very last line saying "error:T.loc:cannot change constant value". Im trying to save the turfs so that it saves all the vars attached to them. please help

You need to make a new turf.
In response to Xx Dark Wizard xX
proc
SaveTurfs() //This is the Save proc.
var/savefile/F = new ("turfs.sav") //creates the save file
var/list/L = new
for(var/turf/doorway/T in world)
T.saved_x = T.x //these tell the game to save the objects
T.saved_y = T.y //location.
T.saved_z = T.z
T.keys = T.keyholders
T.housenos = T.houseno
T.isowned = T.owned
L += T
F[""] << L

proc/LoadTurfs() //Its time to load the objs!
var/savefile/F = new ("turfs.sav")
var/list/L = new
F[""] >> L
if(!L) return
for(var/turf/doorway/T in world) if(T.loc) del(T)
for(var/turf/doorway/T in L)
new T(locate(T.saved_x,T.saved_y,T.saved_z))
T.keyholders = T.keys
T.houseno = T.houseno
T.owned = T.isowned


ok i got this. and added more but now when i exicute LoadTurfs() it reloads my characters loads the mob...
In response to Chase_Hammer
ok i jus tested it again...it didnt reload my mob but it does delete the turf that is there and doesnt replace it so where the doorway use to be is now a empty block.
In response to Chase_Hammer
What's the point with the duplicate vars 'keys' and 'isowned'? They're useless, get rid of them.
Also, you should manage coordinate saving by overidding the Write() and Read() procs, opposed to adding dummy variables to the mob. This is explained in chapter 12 of the DM Guide.

After you clean those up I'll see about the rest. Note that you're saving all the turf's variables, but there are some you will want not to save/restore, namely the contents var. That will also save everything that's in/on the turf when it's being saved, which is probably why it also once saved and reloaded your mob; you don't want that.
In response to Kaioken
i cannot use Write and Read for turf proc. it comes back error saying invalid proc.
In response to Chase_Hammer
Obviously you've done something incorrectly. Post your code so we may spot it.
In response to Kaioken
proc
SaveTurfs()
var/savefile/F = new("turfs.sav")
for(var/turf/doorway/T in world)
F["saved_x"] << T.x
F["saved_y"] << T.y
F["saved_z"] << T.z
Write(F)
In response to Chase_Hammer
any help?
In response to Chase_Hammer
You need to actually understand procs and operators before you use them. Look up the Read() and Write() procs in the DM Reference and figure out how to use them properly. Also, looking up the savefile operators '<<' and '>>' can't hurt either.
In response to Kaioken
i use this same type coding to save the normal character but when tring to save the turf it doesnt want to work. now what.
In response to Chase_Hammer
So what? Thanks to a DM shortcut, Write() and Read() compiles and works properly for your mob-attached saving/loading verbs/procs. You need to properly understand those procs, what they belong to, and therefore how to call them.
And even if that code compiled, you'd be dumping all the turfs' vars into the same savefile dirs, which can screw things up if some order (in the savefile or looping) changes, you better have a unique dir for each turf etc.
Also, are the turfs also going to be created by the map? At any case, you can probably just dump all the turfs into different dirs, loop threw them, reading the coordinates, creating a new turf at that loc and then calling it's Read() proc.
In response to Kaioken
no the save will not create turfs, basically i only want to save the owners/vars of a turf not really the actual turf itself.
In response to Chase_Hammer
i got it...not with Read or Write but by just using my original thoughts on this matter and saving only the string...thanks for the guidance.
In response to Chase_Hammer
Yes, I also suggested in the other topic to possibly save only the string in a unique dir. :P
Well, for that Read() and Write() won't be need to be understood, they won't even be called, but you should still understand them. A lot of people here don't. I guess I shall understand them since you've given up doing that on your own anyway (BAD you, really, it's not that hard). They're similar (but not the same) to using the '<<' savefile operator with an object on the right-hand side, but the important, missed part is that they obviously BELONG TO AN OBJECT. Most people just write things like 'Read(F)' in their code, and that frequently works because Dream Maker assumes 'src' as the object the proc is to be called on, and compiles the line as 'src.Read(F)' instead, and that is obviously frequently correct. A funny (or sad, depending on how you look at it) thing is that people often use Read() and Write() even on savefiles where no objects are saved, because they think these do the actual saving/reading or whatnot. Then they wonder why it 'magically' saves and reloads their mobs and whatnot.
Therefore, in your proc, 'Write(F)' did not work since it didn't belong to a datum therefore the compiler couldn't fill it in to 'src.Write(F)' -- so you got a compile error for an inexisting proc. Since the proc belongs to the object being read/written, you'd want to do 'T.Write(F)' there.