ID:149786
 
I got this from deadrons tut. but I can't get a Save() verb to work:
client/proc/SaveMob()
var/savefile/F = new("players.sav")
var/char_ckey = ckey(mob.name)
F["[ckey]/[char_ckey]"] << mob

client/proc/LoadMob(char_ckey)
var/savefile/F = new("players.sav")
F["[ckey]/[char_ckey]"] >> mob

mob/player/Login()
var/savefile/F = new("players.sav")

// What characters does this player have?
F.cd = "/[ckey]"
var/list/characters = F.dir

// Put together the menu options.
var/newCharacterChoice = "<Create new character>"
var/list/menu = new()
menu += characters
menu += newCharacterChoice

// Find out which character they want to play.
var/result = input("Choose a character or create a new one", "Who do you want to be today?") in menu

if (result == newCharacterChoice)
name = CreateNewCharacter()
else
// We need to get the full name for this character,
// which is stored in the safefile at '/player_ckey/character_ckey/full_name'.
F.cd = "/[ckey]/[result]"
F["full_name"] >> name
client.LoadMob(result)
return ..()

mob/player/proc
CreateNewCharacter()
var/char_name = input("What is the character's name?", "New character") as text
SaveCharacter(char_name)
return char_name

SaveCharacter(char_name)
var/savefile/F = new("players.sav")

// Get the ckey() version of the name to avoid illegal characters for a directory name.
var/safe_name = ckey(char_name)

// Move to the directory for this character, which is:
// /player_ckey/character_ckey
F.cd = "/[ckey]/[safe_name]"

// Storing the actual name as a value (not a directory), so we don't have to worry about what characters it has.
F["full_name"] << char_name

mob/player
verb
Save()
client.SaveMob()


P.S. It's a runtime error:
runtime error: Cannot execute null.SaveMob().
proc name: Save (/mob/player/verb/Save)
usr: Nova (/mob/player)
src: Nova (/mob/player)
call stack:
Nova (/mob/player): Save()
I don't know much about the save script, but i do know that there are many libraries and demos involving save scripts. maybe you should try there.
In response to Canar
Canar wrote:
I don't know much about the save script, but i do know that there are many libraries and demos involving save scripts. maybe you should try there.

I'm using Deadrons Tutorial (as I said in my first post) It's just I can't seem to invoke the saving through a verb.
Nova2000 wrote:
mob/player
verb
Save()
<font color=#ffffa0>client</font>.SaveMob()

P.S. It's a runtime error:
runtime error: Cannot execute <font color=#ffffa0>null</font>.SaveMob().
proc name: Save (/mob/player/verb/Save)
usr: Nova (/mob/player)
src: Nova (/mob/player)
call stack:
Nova (/mob/player): Save()

The problem is that the mob you are trying to save has no client. The default src setting for mob verbs is "set src = usr" so you shouldn't be able to invoke the verb for any mob but your own. It's very puzzling that this is happening.

Is there some other proc calling the Save() verb? Did you change the src setting? What do you do that leads up to the error?
In response to Shadowdarke
That is weird...I can't see the problem either...

It says the usr and src are Nova (I'm assuming that's your character) so it should work...

As Shadowdarke said, the only problem that I can think of would be that it' s being called from somewhere else...but that shouldn't be true because the path (stack) starts at the Save verb...

Is that all of the error or did you not cut and paste all of it?
Nova2000 wrote:
mob/player
verb
Save()
client.SaveMob()

I see the problem! It's very subtle and in this case was particularly hard to spot; it's not surprising you've had so much trouble finding it. I only noticed it because it's similar to a problem I answered on Newbie Central. It stems from the way the verb is defined; because you don't use "set src=usr" in the verb, it assumes that the src object for the verb is "set src in oview(1)". Thus src isn't the object you think it is when you use the verb, and the error ensues.

For the most robust fix, change this to:
mob/player
verb
Save()
set src=usr
usr.client.SaveMob()

Lummox JR
In response to Lummox JR
Did what you said... but still got the error. But:

Second to last line under the Login():

client.LoadMob(result)

If I comment it out... it works (I think, I can't load the data back to see if it did!)

But why should this effect something?