ID:266653
 
OK

well
for a few days now I've been trying to learn the saving system...

and I'vebeen playing around
and I don't understand why it doesn't work, maybe someone can explain it to me...

What this is trying to do is save every mob in the world, then beable to load up every mob in the world where they were when I saved them...
mob/verb/WorldSave()
world<<"World saving!! Saving world every 6 minutes. Lag monster coming!! Please hold."
spawn
for(var/mob/M as mob in world)
M.Save(M)
return
mob/proc/Save()
var/savefile/F=new("worldsave.sav")
F.cd="[src.ckey]"
F["[ckey]"]<<src
F["x"]<<src.x
F["y"]<<src.y
F["z"]<<src.z
F["icon"]<<src.icon
return
mob/proc/Loadworld()
var/thex
var/they
var/thez
var/thei
var/them
world<<"Loading saved world..."
var/savefile/F=new("worldsave.sav")
for(F.cd in F.dir)
F["[ckey]"]>>them
F["x"]>>thex
F["y"]>>they
F["z"]>>thez
F["icon"]>>thei</<src></<src></&l t;src></<src></<src>
It looks like you've got some of the basics down, but your load proc needs work. Take a look:

mob/proc/Loadworld()
var/thex
var/they
var/thez
var/thei
var/them
world<<"Loading saved world..."
var/savefile/F=new("worldsave.sav")
for(F.cd in F.dir)
F["[ckey]"]>>them
F["x"]>>thex
F["y"]>>they
F["z"]>>thez
F["icon"]>>thei

What you've done there is assign vars from the savefile into temporary vars which then never get used; you've loaded everything up and immediately thrown it away. (There could be other problems in here I don't see, but the big one is that you're not using what you're loading.)

To fix this, you should recode as follows:
mob/proc/Loadworld()   // this probably should be a global proc
var/thex
var/they
var/thez
var/mob/M
world<<"Loading saved world..."
var/savefile/F=new("worldsave.sav")
for(F.cd in F.dir)
F["[ckey]"] >> M
F["x"] >> thex
F["y"] >> they
F["z"] >> thez
M.loc=locate(thex,they,thez)
F["icon"] >> M.icon

Now, one thing I should mention: Saving icons in your file is not a very good idea. They take up inordinate space, so if you can regenerate them at load time instead, you should do that. What you probably should do is create a var indicating which icon out of a possible set is in use by the player's mob, then save that.

Of course, in reality the icon should already be saving as part of the mob. To save your saves and loads a lot of stress (and disk space), override the default saving to temporarily set each mob's icon to null before you save it.

Lummox JR
In response to Lummox JR
thanks a ton!!! Been trying to make this work for forever! :P


runtime error: Cannot modify null.loc.
proc name: Loadworld (/mob/proc/Loadworld)
source file: Saving.dm,28
usr: Mardul (/mob/God/Mardul)
src: Mardul (/mob/God/Mardul)
call stack:
Mardul (/mob/God/Mardul): Loadworld()
Mardul (/mob/God/Mardul): World Menu()


I get that
for this...
mob/proc/Loadworld()
var/thex
var/they
var/thez
var/mob/M
world<<"Loading saved world..."
var/savefile/F=new("worldsaved.sav")
for(F.cd in F.dir)
F["[ckey]"]>>M
F["x"]>>thex
F["y"]>>they
F["z"]>>thez
M.loc=locate(thex,they,thez)


I took saving the icon out...
In response to Jon Snow
Jon Snow wrote:
runtime error: Cannot modify null.loc.

This means that M isn't being loaded correctly, and the var is remaining null after it's loaded.

Looking at your code again, I think the load routine is now close to right but the save is messed up. You're trying to save in the directory "[src.ckey]", but src is a mob, not a client. This could be a big problem.

Another problem is that you're using "[ckey]" again when loading the mob. For that you should be using "[F.cd]", since the mob is being saved to the same value as the name of its directory.

Lummox JR
In response to Lummox JR
hmm this is interesting...

Ok so I hit saveworld then it saved and what you said worked it loaded me to my mob from when I saved it right there...

But one problem... big problem. The icons show and the verbs work but when you right click on the mob nothing shows up...

Also after loading the world once when trying to load it again it gave me thatsame error it gave me last time...