ID:144163
 
Code:
mob
Write(savefile/f)
..()
src.x>>f["x"] //<-- line 6
src.y>>f["y"]
src.z>>f["z"]
Read(savefile/f)
var x,y,z
x<<f["x"]
y<<f["y"]
z<<f["z"]
src.Move(locate(x,y,z))


mob/proc
Save()
var/savefile/f=new("saves/[src.ckey]/mobs.sav")
var/cname=cKey(src.name)
f["[cname]"]<<src

Load(cname)
var/savefile/f=new("saves/[src.ckey]/mobs.sav")
if(!fexists(f)) return
client.mob<<f["[cname]"]
PlayerList()
var/savefile/f=new("saves/[src.ckey]/mobs.sav")
return f.dir


mob/Choosing
Login()
CHOOSE
switch(input(src,"Welcome! What do you wish to do?") in list("New Game","Load Game","Quit"))
if("New Game")
Create()
if("Load Game")
var/savefile/f=new("saves/[src.ckey]/mobs.sav")
if(!fexists(f))
alert(src, "No savefile...")
goto CHOOSE
var/list/players=PlayerList()
var/choice=input("Which character do you want to load?") in players
Load(choice)
if("Quit")


Problem description:
I get a problem of "bad input src" during runtime at line 6. This code most likely stinks and everyone will be having ulcers looking at it. Saving systems aren't my strong point.

LastTroubadour wrote:
Code:
>       src.x>>f["x"] //<-- line 6
> src.y>>f["y"]
> src.z>>f["z"]

> x<<f["x"]
> y<<f["y"]
> z<<f["z"]


I get a problem of "bad input src" during runtime at line 6.

Well, among other problems. But I'm not in the mindset to sit and write a long post, so I'll address this problem exclusively.

When reading and writing with savefiles, you use the << and >> operators with the savefile part as the left operand, and the variable as the right operand. What this means is that, instead of something like this:
X >> f["x"]

you would do this:
f["x"] << X

As always, data "flows" in the direction of the operators, so the above mentioned example would write to the savefile (with the data in X "flowing" to the savefile), and this would read to X:
f["x"] >> X



Hiead
In response to Hiead
Okay, that problem is fixed. Now the Load() proc isn't detecting the savefile. The file is there, I checked.
In response to LastTroubadour
LastTroubadour wrote:
Now the Load() proc isn't detecting the savefile. The file is there, I checked.

Actually, it is detecting the file as it should. You are improperly using fexists(), though, and so your Load() proc will always return prematurely.
       var/savefile/f=new("saves/[src.ckey]/mobs.sav")
if(!fexists(f)) return

According to the DM reference, the fexists proc takes one argument:

File: name of file to test

Therefore, you would pass to fexists() the filename, and not a savefile.

Hiead
In response to Hiead
Yeah. Here is a correct code example (with a tiny personal trick that you don't have to type/copy the filepath twice :)).
var/savefile/SF = "saves/[M.ckey].sav" //first, set the var to the text string of the filepath
if(!fexists(SF)) return 0 //stop if the file doesn't exist.
SF = new(SF) //re-use the text string we've made earlier
In response to Kaioken
I got it to work. Thanks for the help.