ID:138446
 
I hate going to the message boards to get help with a snippet but this time I'm really stumped. What I'm trying
to do is allow players to recruit player mobs in their oview() into their guild. It all works fine until I use
the SaveGuild() proc which saves the new list of members
created after the JoinGuild() proc. As soon as the SaveGuild() proc is executed the Dream Seeker runs the Login() proc again for some reason.

This is the proc executed by the player to recruit someone:

JoinGuild()
if(usr.guildcptn != usr.name)
usr << "Only captains can initiate people into their guild."
return
usr << "Who are you going to bring into your guild?"
var/mob/who
var/people[0]
for(who as mob in oview(usr))
if(who.id == 1000)
people += who
if(people.len == 0)
usr << "Nobody here to recruit."
return
who = prompt("Recruit who?") in people
if(who == null)
return
who:Recruit()
return

This is the proc sent to the person being recruited:

Recruit()
src << "[usr.name] wants to recruit you into his guild which"
src << "is called [usr.guildnm]."
var/yn = prompt(src,"Join?") in list("yes","no")
if(yn == "yes")
usr << "[src.name] has joined your guild and is now ranked Private."
src.guildnm = usr.guildnm
src.guildcptn = usr.name
src.guildprfx = usr.guildprfx
src.guildlst = usr.guildlst
src.guildrank = "Private"
var/GUY = src
usr:SaveGuild(GUY)
return
if(yn == "no")
usr << "[src.name] decided not to join your guild."
return

Lastly, this is the proc that saves the new list. I'm pretty sure this is where the crash occurs because the last
thing I see before the crash is "[src.name] has decided to join your guild."

SaveGuild(GUY)
var/people[0]
var/savefile/Q = new /savefile("[usr.guildprfx].sav")
Q["guildlst"] >> people
people += GUY
Q["guildlst"] << people
del(Q)
return
I think I know what's going on, but it may take a bit of explaining. First off, you say that the program crashes when you do a save? Do you mean that Dream Seeker causes an "assertation fault", or you get a proc crash, or a blank map, or what? If it is a proc crash, what is it outputting.

I'm guessing that when you call SaveGuild() your mob is transported to the null loc via Login(). The reason this happens is because you are saving your guilds as lists of mobs. The entire mob data is stored in the guild list, and when you retrieve it these mobs are recreated and any existing mobs on the map are logged back into the new versions. One of the tutorials explains the Login() process a bit better. I have to admit that it is a little confusing, but hopefully that will clear it up.

Rather than save the guilds as lists of mobs, I would suggest saving them as lists of mob keys or some other such identification (eg: guildlist += GUY.ckey). When you reload the guildlist you can check for mobs in the world that have the corresponding key and set them in the appropriate guild.

Does this make any sense?
In response to Tom H.
You were right. Thanks for the help.