ID:147946
 
with the following code I get this error:
runtime error: Cannot read null.mob
proc name: Save (/mob/proc/Save)
usr: Delita12345 (/mob)
src: Delita12345 (/mob)
call stack:
Delita12345 (/mob): Save()
Delita12345 (/mob): CreateNewChar()
Delita12345 (/mob): Login()

the code is
mob
Login()
..()
if(src.created == 1)
src.Load()
..()
else
src.CreateNewChar()

proc
Save()
var/key_letter = copytext(src.key,1,2)
var/safe_name = ckey(src.key)
var/savefile/F = new("Players/[key_letter]/[safe_name].sav")
F["mob"] << src.client.mob
Load()
var/key_letter = copytext(src.key,1,2)
var/safe_name = ckey(src.key)
var/savefile/F = new("players/[key_letter]/[safe_name].sav")
F["mob"] >> src.client.mob
CreateNewChar()
var/char_name = input("What is your name?","Character Creation",src.key)
var/list/avatars = list("Lan","Mayl","Dex","Yai","Chaud")
var/mob/character
var/avatar = input(src,"Which avatar would you like?","Character Creation") in avatars
switch(avatar)
if("Lan")
character = new /mob/GM()
if("Mayl")
character = new /mob/avatar/Mayl()
if("Yai")
character = new /mob/avatar/Yai()
if("Dex")
character = new /mob/avatar/Dex()
if("Chaud")
character = new /mob/avatar/Chaud()
character.name = char_name
character.key = src.key
src.Save()
return ..()
Delita12345 wrote:
with the following code I get this error:
runtime error: Cannot read null.mob
proc name: Save (/mob/proc/Save)
usr: Delita12345 (/mob)
src: Delita12345 (/mob)
call stack:
Delita12345 (/mob): Save()
Delita12345 (/mob): CreateNewChar()
Delita12345 (/mob): Login()

the code is
mob
> Login()
> ..()
> if(src.created == 1)
> src.Load()
> ..()
> else
> src.CreateNewChar()
>
> proc
> Save()
> var/key_letter = copytext(src.key,1,2)
> var/safe_name = ckey(src.key)
> var/savefile/F = new("Players/[key_letter]/[safe_name].sav")
> F["mob"] << src.client.mob
> Load()
> var/key_letter = copytext(src.key,1,2)
> var/safe_name = ckey(src.key)
> var/savefile/F = new("players/[key_letter]/[safe_name].sav")
> F["mob"] >> src.client.mob
> CreateNewChar()
> var/char_name = input("What is your name?","Character Creation",src.key)
> var/list/avatars = list("Lan","Mayl","Dex","Yai","Chaud")
> var/mob/character
> var/avatar = input(src,"Which avatar would you like?","Character Creation") in avatars
> switch(avatar)
> if("Lan")
> character = new /mob/GM()
> if("Mayl")
> character = new /mob/avatar/Mayl()
> if("Yai")
> character = new /mob/avatar/Yai()
> if("Dex")
> character = new /mob/avatar/Dex()
> if("Chaud")
> character = new /mob/avatar/Chaud()
> character.name = char_name
> character.key = src.key
> src.Save()
> return ..()

ehh...

client
New()
//there is a new person in the world, but they might not have a mob yet
..()
Del()
//the person is about to leave
//save the person here
..() //delete them
mob
Login()
//ok the person is in, and they now have a valid mob connected to them
//check for old char, load em
//if not, call char creation
..() //we done with login
In response to FIREking
I sudgest not copying and pasting codes you dont understand, the most understandable code is something you coded so why not check out a lib or 2 and make up your own character creation? This way you'll fully understand it and when there comes a bug you'll know what to do.
Delita12345 wrote:
with the following code I get this error:
runtime error: Cannot read null.mob
proc name: Save (/mob/proc/Save)
usr: Delita12345 (/mob)
src: Delita12345 (/mob)
call stack:
Delita12345 (/mob): Save()
Delita12345 (/mob): CreateNewChar()
Delita12345 (/mob): Login()

It helps to turn on debugging in Build | Preferences so you can get a line number to go with the error. In this case it's obvious, though: It's the line with src.client.mob in Save().

I'm guessing you're using the same load/save code that's been screwing everyone else up, or something similar to it. If your Logout() calls Save(), you'll have the same error there, because during Logout() client can no longer be trusted.

the code is
mob
Login()
..()
if(src.created == 1)
src.Load()
..()
else
src.CreateNewChar()
Problem off the bat here: It's not an especially good idea to use the same /mob type for regular mobs and for login. Easier is to create a /mob/creating_character type, set world.mob to that, and then create a special mob/creating_character/Login().

Also, there's absolutely no point in calling ..() twice. The first call is the one you should ax, if you don't switch to a two-type login, because a new mob shouldn't be placed in the world yet.

    proc
Save()
var/key_letter = copytext(src.key,1,2)
var/safe_name = ckey(src.key)
var/savefile/F = new("Players/[key_letter]/[safe_name].sav")
F["mob"] << src.client.mob
As mentioned, this isn't especially a safe idea. You can't count on src.key or src.client being anything if this is called during Logout(). I'd make a copy of the key in another var, and use that in place of src.key. Instead of src.client.mob, just use src.
        Load()
var/key_letter = copytext(src.key,1,2)
var/safe_name = ckey(src.key)
var/savefile/F = new("players/[key_letter]/[safe_name].sav")
F["mob"] >> src.client.mob
src.key makes sense here, as does src.client.mob.
        CreateNewChar()
...
character.name = char_name
character.key = src.key
src.Save()
return ..()
Problems: src is the mob you logged in under, not the character, so you shouldn't save it; that's one reason why you've got the error here. After the character.key=src.key line, the player transfers to the new character; you should use character.Save() instead of src.Save(). Also, ..() is meaningless here, because this proc is brand new; ..() means "Call the old version of this proc."

Lummox JR
In response to Crashed
you know, the funny thing is, I did code this myself. I didn't copy anything whatsoever.
In response to Lummox JR
ok, I have some new code, but now the mob doesn't save. whenever you log in, it asks for your name and avatar again.
mob/choosing_char
Login()
if(src.created == 1)
src.Load()
..()
else
src.CreateNewChar()

mob
proc
Save()
//var/key_letter = copytext(src.key,1,2)
var/safe_name = ckey(src.name)
var/savefile/F = new("Players/[safe_name].sav")
F["mob"] << src
Load()
var/key_letter = copytext(src.key,1,2)
var/safe_name = ckey(src.key)
var/savefile/F = new("players/[key_letter]/[safe_name].sav")
F["mob"] >> src.client.mob
CreateNewChar()
var/char_name = input("What is your name?","Character Creation",src.key)
var/list/avatars = list("Lan","Mayl","Dex","Yai","Chaud")
var/mob/character
var/avatar = input(src,"Which avatar would you like?","Character Creation") in avatars
switch(avatar)
if("Lan")
character = new /mob/avatar/Lan()
if("Mayl")
character = new /mob/avatar/Mayl()
if("Yai")
character = new /mob/avatar/Yai()
if("Dex")
character = new /mob/avatar/Dex()
if("Chaud")
character = new /mob/avatar/Chaud()
character.name = char_name
character.key = src.key
character.created = 1
character.Save()
return

PS: I really appreciate all the help I'm getting.
In response to Delita12345
Delita12345 wrote:
ok, I have some new code, but now the mob doesn't save. whenever you log in, it asks for your name and avatar again.

You commented out the var/key_letter line in the save proc, but loading still uses it.

What you really need to do instead of commenting out the line is to replace key with another var. I'd save the key to another var on Login(), like mykey. Then use that var when you save.

I don't think it's possible to load and save safely under the login system you've got going on now, though. You need to create a new mob type and handle character creation under that.

Lummox JR
In response to Lummox JR
you know what? this is so confusing. could you just write me snippet of Login code? I'll see what I can do from there.
In response to Delita12345
Delita12345 wrote:
you know what? this is so confusing. could you just write me snippet of Login code? I'll see what I can do from there.

You might want to look into this library:

http://developer.byond.com/hub/Deadron/CharacterHandling

You can either use it directly as a library (there is a complete demo showing how to do this) or look at the code in the library to see how it's being done.
In response to Delita12345
Oh, it looks like you did i didn't look at the code i just took a look at the text thinking it was another noob using the Character Creation by Deadron, or someone of that nature. Sorry i miss judged you.
In response to Deadron
Deadron wrote:
Delita12345 wrote:
you know what? this is so confusing. could you just write me snippet of Login code? I'll see what I can do from there.

You might want to look into this library:

http://developer.byond.com/hub/Deadron/CharacterHandling

You can either use it directly as a library (there is a complete demo showing how to do this) or look at the code in the library to see how it's being done.

I've looked at that, tried to implement it to my own liking and such, SO many times. I don't know what it is about the savefiles, but that's the only thing that really stumps me in DM.
In response to Delita12345
Delita12345 wrote:
I've looked at that, tried to implement it to my own liking and such, SO many times. I don't know what it is about the savefiles, but that's the only thing that really stumps me in DM.

The best I can do is point you to this if you haven't seen it already; it's the clearest explanation I can provide:

http://www.deadron.com/Games/ByondBasicSavefiles.html