ID:2036619
 
(See the best response by Ter13.)
Code:
world
mob = /mob/other/choosing_character
name = "One Punch Man"
hub_password = "omolewa"
view = 7
fps = 10
version = 1.0
status = "<B><font size = -2><font color = green>One Punch Man</font> <font color = purple>{Version Beta 1.0}</font>"
hub = "Dragonpearl123.onepunchman"
sleep_offline = 0
map_format = TOPDOWN_MAP
icon_size = 32



var/list/_races = list("Human"=/mob/characters/Human, "Mage"=/mob/characters/Mage) //obviously, modify this to suit your races.

client
var/tmp
mob/oldmob
proc
Save()
if(oldmob&&oldmob.savable)
var/savefile/savefile = new("players/[copytext(ckey, 1, 2)]/[ckey].sav")
savefile["/[ckey]/[ckey(mob.name)]"] << oldmob
Del()
Save()
..()

mob/other/choosing_character
var
list/characters = list()
savefile/savefile
Login()
client.eye = locate(rand(1,150),rand(1,150),1)
client.perspective = EYE_PERSPECTIVE
spawn()
ChooseCharacter()

proc
ChooseCharacter()
//we don't need to reload the savefile more than once. Store it and keep the chars list around
savefile = new("players/[copytext(ckey, 1, 2)]/[ckey].sav")
savefile.cd = "/[ckey]"
characters = savefile.dir
var/list/menu //it's best to define these outside of a loop where possible. There are reasons.
var/result
while(client)
menu = characters + "New Character" + "Delete Character"

result=input("Choose an option", "One Punch Man") as anything in menu
switch(result)
if("New Character")
CreateNewCharacter()
if("Delete Character")
DeleteCharacter()
else
LoadCharacter(result)

DeleteCharacter()
var/result = input("Delete character", "Character Creation") as null|anything in characters

if (result)
savefile.dir.Remove(result)
characters -= result

CreateNewCharacter()
var/char_name
do
char_name = input(src, "What is your name?","New Character") as null|text
if(!char_name)
return
if (ckey(char_name) in characters)
alert("This name isn't acceptable.")
char_name = null
while(!char_name)

var/char_race = input(src, "What race do you wish to be?", "New Character", "Human", "Mage") in _races
var/rtype = _races[char_race]
var/mob/new_mob = new rtype()
new_mob.client = client //after creating the new character, you need to set the new mob's client to end the character creation process and suspend the loop.
new_mob.savable = 1
new_mob.name = char_name
savefile[ckey(char_name)] << new_mob //save the character in the savefile before this mob is garbage collected.

LoadCharacter(char)
var/mob/m
savefile[char] >> m
m.savable = 1 //shouldn't be necessary, but in case you don't want to purge your savefiles.
//if(client) m.client = client //this should never happen, but just in case something goes wrong we'll put it here anyway to be safe


mob
var
savable = 0

Login()
if(client.oldmob) client.Save()
client.oldmob = src
src.loc=locate(44,39,1)
src.icon_state = ""
src.sight = 0
client.eye = src
client.perspective = MOB_PERSPECTIVE
src << output("<b><font color = red>Welcome to One Punch Man The Game, we owe no affiliation to one punch man so don't sue us XD</font>","system")
world << output("<font color=purple><b>[name] has joined the ranks</b></font>", "chatbox")
sample_report()

Logout()
client.Save()
del src

Write(savefile/F)
if(!savable) return
..()

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)

proc
sample_report()
src << output("<b><font size = 1><font color = silver><center>By: Dragonpear321","system")
src << output("<b>Beta Testing One Punch Man","system")


Problem description:
This is really starting to grind my gears, the game will not save anything and I am getting these runetime errors.

runtime error: Cannot execute null.Save().
proc name: Logout (/mob/Logout)
source file: Start.dm,110
usr: (src)
src: Dragonpearl123 (/mob/other/choosing_character)
src.loc: null
call stack:
Dragonpearl123 (/mob/other/choosing_character): Logout()
Dragonpearl123 (/mob/other/choosing_character): CreateNewCharacter()
Dragonpearl123 (/mob/other/choosing_character): ChooseCharacter()
Dragonpearl123 (/mob/other/choosing_character): Login()

Can someone please help me!!!
You are trying to save the mob's client after they have already disconnected. By the time mob/Logout() is called, the client is already gone. You will have to save the client before Logout() happens, and always make sure the client still exists before doing so.
In response to Multiverse7
Thanks for the reply, but I see no other instance in where the client would have logged out + I put that and it now saves but I still get runetime errors
What other runtime errors are you getting? The error that you provided suggests that something.Save(), which is probably client, is being called when the src object doesn't exist.

It looks like you might be trying to save the client as part of your mob character's creation, before any client has actually been associated with it. You need to connect the client to a mob, before you try saving the client, via the mob. However, it may be best to do mob things in the mob and client things in the client, so that you don't run into these problems.
In response to Multiverse7
runtime error: Cannot execute null.Save().
proc name: Logout (/mob/Logout)
source file: Start.dm,110
usr: (src)
src: Dragonpearl123 (/mob/other/choosing_character)
src.loc: null
call stack:
Dragonpearl123 (/mob/other/choosing_character): Logout()
the asca (/mob/characters/Human): Read(players/d/dragonpearl123.sav (/savefile))
Dragonpearl123 (/mob/other/choosing_character): LoadCharacter("asca")
Dragonpearl123 (/mob/other/choosing_character): ChooseCharacter()
Dragonpearl123 (/mob/other/choosing_character): Login()

Those are about it nothing else!!
Actually, I think you forgot to call ..() under Login().
In response to Multiverse7
Start.dm:108:error: proc definition not allowed inside another proc
Edit: Oh wait nvm, but it still didnt fix anything.
In mob/Login() and mob/other/choosing_character/Login(), you should place ..() before everything else. Otherwise, there will be no client to access. The client will never finish connecting to the mob.

..() represents the default action of a proc. Calling it will run both the built-in default behavior, as well as behavior that is defined in the parent type's version, and so on.
In response to Multiverse7
I get more errors now
runtime error: Cannot execute null.Save().
proc name: Logout (/mob/Logout)
source file: Start.dm,114
usr: (src)
src: Dragonpearl123 (/mob/other/choosing_character)
src.loc: null
call stack:
Dragonpearl123 (/mob/other/choosing_character): Logout()
the lolmasd (/mob/characters/Human): Read(players/d/dragonpearl123.sav (/savefile))
Dragonpearl123 (/mob/other/choosing_character): LoadCharacter("lolmasd")
Dragonpearl123 (/mob/other/choosing_character): ChooseCharacter()
Dragonpearl123 (/mob/other/choosing_character): Login()
runtime error: Cannot read null.oldmob
proc name: Login (/mob/Login)
source file: Start.dm,100
usr: (src)
src: Dragonpearl123 (/mob/other/choosing_character)
src.loc: null
call stack:
Dragonpearl123 (/mob/other/choosing_character): Login()
Dragonpearl123 (/mob/other/choosing_character): Login()
Add if(client) to Login() and indent everything under it, except for ..(), which should still come first.
In response to Multiverse7
I did that and it also did not work.
Best response
We already fixed this in an earlier thread. You just accidentally left a line in that I'm 90% sure I told you to remove. Remove client.Save() from mob/Logout().

In response to Ter13
I know you told me to remove that, but then it wouldn't save on logout, and it would still give me the runtime errors.
I know you told me to remove that, but then it wouldn't save on logout

Actually, we moved the saving to client/Del(). The client is already gone by the time Logout() is called, so you can't call a client proc on it in Logout(). I thought I explained this all really thoroughly.
In response to Ter13
I know you explained it thoroughly but if I do this I get a host of errors.
1. usr/src is defined as the race not the actual character name.
2. New characters that are made dont save...at all!
3.It basically jacks up my game :D
Okay, well that's the first you've even mentioned that. We need to look at those errors that happen when we change that bit.

See, I gave you some bad advice a few weeks back and it caused a small problem.

Now that we know that problem exists, we're trying to fix it.

You can't expect me to be able to help you fix anything if you aren't showing me the problems.

client.Save() in Logout() is absolutely causing runtime errors. Refusing to fix that makes zero sense at all. I don't understand why you are being so deliberately obstinate about all of this. Show me the errors that occur when you remove client.Save() in mob/Logout().
In response to Ter13
That's the thing, (sorry for my stubbornness) when I remove it I get absolutely zero errors both runetime and debug. But things like

world << output("<font color=purple><b>[src] has joined the ranks</b></font>", "chatbox")


and

stat("[rank] [usr.name]", "")

tend to only show 'Human' or 'Mage' (Depending on race) instead of usr.name src.name src, and usr.
Dragonpearl123 wrote:
I know you explained it thoroughly but if I do this I get a host of errors.

Dragonpearl123 wrote:
That's the thing, (sorry for my stubbornness) when I remove it I get absolutely zero errors both runetime and debug.

Perhaps you can understand my confusion.

Please just PM me a zip file with the source code. I'd like to take a poke myself without bringing the Tower of Babel back for a reunion tour.
In response to Ter13
Sure ill pager it to you asap!
Edit: Sent it.
Will take a look when I get back. Heading out to dinner for the woman's birthday.
Page: 1 2