Well, Deadrons library is great and all (Thanks Deadron!), but I thought I better learn how to manage my own savefiels sooner or later, so I went and read his FAQ entry about it and have been busy working on it for the past week. I seem to have most of it down, the newly created mobs are being saved correctly, and deleting works fine... But. I can't seem to load anything. It seems to get stuck ina loop of some sort.
My world/mob is choosingcharacter, and my choosingcharacter Login() called a ChooseCharacter proc with all the creation options and stuff. This works fine for a first time player, because the CreateCharacter proc switches the src's client.mob to a new /mob/player. Unfortunately though, when they try to load a mob, it just goes right back to the character selection screen. (Snippet below). Is it safe to assume that this is because its calling mob/choosingcharacter/login after it loads the info from the savefile?
ChooseCharacter()
var/player_sav = "Players/[ckey(src.key)].sav"
var/savefile/F = new(player_sav)
F.cd = "/[ckey]"
var/list/characters = F.dir
var/NewCharacterChoice = ""
var/DeleteCharacterChoice = ""
var/list/menu = new()
menu += characters
menu += NewCharacterChoice
menu += DeleteCharacterChoice
var/result= input(src, "Choose an adventurer","Character Select", null) in menu
if (result == NewCharacterChoice)
name = CreateNewCharacter()
if (result == DeleteCharacterChoice)
DeleteCharacter()
else
src << "You chose to play [result]"
loadmob(result)
loadmob(char_key)
var/player_sav = "Players/[ckey(src.key)].sav"
var/savefile/F = new(player_sav)
F.cd = "/[ckey]/[char_key]"
// var/mob/loadedmob
F >> src
/* src.client.mob = loadedmob //Line 110
del(src)*/
I thought maybe I could use the same approach as I did for creating new mobs, after all, change the mob to something other than choosingcharacter and it shouldn't have to use choosingcharacter(Login), unfortunately, client.mob appears to be null. As you'll see here. I tried src.client.mob, client.mob, usr.client mob, and passing a variable from Login(src), to ChooseCharacter(player), to Loadmob(player) and player.client.mob, none of them worked though.
runtime error: Cannot modify null.mob.
proc name: loadmob (/mob/choosingcharacter/proc/loadmob)
source file: creation.dm,110
usr: Zagreus (/mob/choosingcharacter)
src: Zagreus (/mob/choosingcharacter)
call stack:
Zagreus (/mob/choosingcharacter): loadmob("zagreus")
Zagreus (/mob/choosingcharacter): ChooseCharacter()
Zagreus (/mob/choosingcharacter): Login()
Can anyone please shed some light on this? Been broken for quite awhile now. :)
ID:149383
May 11 2002, 12:21 pm
|
|
In response to RaeKwon
|
|
RaeKwon wrote:
Well, here is a basic character handling. client/proc/LoadMob(char_ckey) I really appreciate your trying to help, really. Src seems to be correct here and all, but src.mob is an undefined variable, and src.client.mob is null. This is what I was trying to explain in my last post, sorry if it wasn't clear enough. |
client/proc/SaveMob()
var/savefile/F = new("players.sav")
var/char_ckey = cKey(src.mob.name)
F["/[ckey]/[char_ckey]"] << src.mob
client/proc/LoadMob(char_ckey)
var/mob/new_mob
var/savefile/F = new("players.sav")
F["/[ckey]/[char_ckey]"] >> new_mob
if (!new_mob)
return 0
else
src.mob = new_mob
return 1
client/Del()
if (istype(src.mob, /mob/other/choosing_character))
return ..()
src.SaveMob()
return ..()
mob/other/choosing_character
Login()
spawn()
src.ChooseCharacter()
proc
ChooseCharacter()
var/list/characters = src.CharacterList()
var/newCharacterChoice = "New Warrior"
var/DeleteCharacterChoice = "Delete Warrior"
var/list/menu = new()
menu += characters
menu += newCharacterChoice
menu += DeleteCharacterChoice
var/result = input("What do you want to do? Delete a Warrior? Create a new one? or play an existing one?", "Warning: Applet Window") in menu
if (result == newCharacterChoice)
src.CreateNewCharacter()
if (result == DeleteCharacterChoice)
src.DeleteCharacter()
src.ChooseCharacter()
else
var/success = src.client.LoadMob(result)
if (success)
del(src)
else
alert("Sorry, unable to load that character!")
src.ChooseCharacter()
CharacterList()
var/savefile/F = new("players.sav")
F.cd = "/[ckey]"
var/list/characters = F.dir
return characters
DeleteCharacter()
var/savefile/F = new("players.sav")
F.cd = "/[ckey]"
var/list/characters = F.dir
var/CancelCharacterDeletion = "Cancel"
var/list/menu = new()
menu += characters
menu += CancelCharacterDeletion
var/result = input("deleting a character", null, "Which character do you want to delete?") in menu
if (result)
F.cd = "/[ckey]"
F.dir.Remove(result)
if (result == CancelCharacterDeletion)
src.ChooseCharacter()
else
src.ChooseCharacter()
mob/other/choosing_character/proc/CreateNewCharacter()
// blah blah for your creation of your character
mob
Login()
..()
if (!istype(src, /mob/other/choosing_character))
Write(savefile/F)
..()
F["last_x"] << x
F["last_y"] << y
F["last_z"] << z
Read(savefile/F)
..()
var/last_x
var/last_y
var/last_z
F["last_x"] >> last_x
F["last_y"] >> last_y
F["last_z"] >> last_z
loc = locate(last_x, last_y, last_z)
world
mob = /mob/other/choosing_character
- RaeKwon