ID:140541
 
Code:
#define DEBUG
mob
proc
Save()
var/savefile/F=new("saves/[src.ckey].sav")
src.Write(F)
F["lastx"] << src.x
F["lasty"] << src.y
F["lastz"] << src.z
F["icon"] << src.icon
F["items"] << src.contents
F["verbs"] << src.client.verbs // this.

Load()
var/savefile/F = new("saves/[src.ckey].sav")
src.Read(F)

var/newx
var/newy
var/newz
F["lastx"] >> newx
F["lasty"] >> newy
F["lastz"] >> newz
src.loc=locate(newx,newy,newz)
F["verbs"] >> src.client.verbs // this.
F["icon"] >> src.icon
F["items"] >> src.contents


Problem description:
I just spent a good 10 minutes searching the forum, only to find that this hasn't come up anywhere.
Closest thing I could find: http://www.byond.com/developer/forum/?id=714727


Look at the commented lines, what would I have to put there in order to save and load the verblist correctly?
I have tried mob.verbs, src.verbs, src.mob.verbs (<-- lol.), and simply client.verbs. :\

I most definitely do not want to have to put them in a list, I've never been good at working with those. haha
Most likely because you are modifying the mob's verbs, not the client's verbs. You would need to save src.verbs instead.

Also note that you are not saving properly. This would be proper:

client
proc
Save()
var/savefile/F = new()
F << mob
Load()
var/savefile/F = new()
F >> mob
New()
Load()
..()
Del()
Save()
..()

mob
//handle all special saving/loading in mob/Write() and mob/Read()
Write(var/savefile/F)
..()
F["x"] << x
F["y"] << y
F["z"] << z
//no need to save icon or contents, they're saved by default
F["verbs"] << verbs
Read(var/savefile/F)
..()
loc = locate(F["x"], F["y"], F["z"])
F["verbs"] >> verbs


Note that for things like verbs and icon, I strongly suggest you instead store the data in other variables, and derive the icon or verbs from that instead. IE: if you want to give the verb "pray" to anybody who is religious, instead save whether they are religious or not and re-give them the verb in Read() if they are religious. Similar deal for icon. The issue is that if you need to change verb paths around for some reason, old savefiles will no longer be valid if you do so. As for icons, the entire file is stored in the savefile otherwise (you will need to do F.dir -= "icon" to prevent saving it) which bloats the file and also means changing the icon leaves people with the old icon.
yea as garthor said give them the verbs when they load their char. according to vars. also this is alot more secure as the host cant give themselves the verb unless they know the var to change. So instead of religous it can be hmm dead2? a host wouldnt think they are remotely connected.

if(src.religous)
src.verbs += typesof(/mob/religous/verb)
In response to Garthor
Garthor wrote:
>     F["verbs"] >> verbs


Note that since the verbs var is read-only, that will generate a runtime error. So you'd need to do something like this to get the above operation to work:
var/saved_verbs
F["verbs"] >> saved_verbs
src.verbs.Cut() //or verbs=null
src.verbs += saved_verbs


Of course, you'd typically not want to do this kind of operation at any case, and instead keep any verbs the player already has (otherwise, verbs that have been added later are lost), meaning you'd skip emptying the list.

The issue is that if you need to change verb paths around for some reason, old savefiles will no longer be valid if you do so.

They're still valid, however reading a now-nonexistent path will cause a (mostly harmless) runtime error.
In response to Rapmaster
Security is not even the remotest of considerations in this point. If you are actually concerned with security, there are far better ways of protecting a savefile. Note, however, that regardless of what you do, if somebody is hosting, they DO have complete control over your game and it would be nearly impossible to do anything about it.
In response to Garthor
Garthor wrote:
Most likely because you are modifying the mob's verbs, not the client's verbs. You would need to save src.verbs instead.

Also note that you are not saving properly. This would be proper:

client
> proc
> Save()
> var/savefile/F = new()
> F << mob
> Load()
> var/savefile/F = new()
> F >> mob
> New()
> Load()
> ..()
> Del()
> Save()
> ..()
>
> mob
> //handle all special saving/loading in mob/Write() and mob/Read()
> Write(var/savefile/F)
> ..()
> F["x"] << x
> F["y"] << y
> F["z"] << z
> //no need to save icon or contents, they're saved by default
> F["verbs"] << verbs
> Read(var/savefile/F)
> ..()
> loc = locate(F["x"], F["y"], F["z"])
> F["verbs"] >> verbs

Note that for things like verbs and icon, I strongly suggest you instead store the data in other variables, and derive the icon or verbs from that instead. IE: if you want to give the verb "pray" to anybody who is religious, instead save whether they are religious or not and re-give them the verb in Read() if they are religious. Similar deal for icon. The issue is that if you need to change verb paths around for some reason, old savefiles will no longer be valid if you do so. As for icons, the entire file is stored in the savefile otherwise (you will need to do F.dir -= "icon" to prevent saving it) which bloats the file and also means changing the icon leaves people with the old icon.

Can't you not call that save on client/Del() because the mob is already gone?
In response to Tubutas
Tubutas wrote:
Can't you not call that save on client/Del() because the mob is already gone?

Yes, if a mob is deleted with del() the mob will be gone before Del() is called. The solution to this is to not delete mobs which have a player connected to them. If you need to disconnect somebody, delete their client instead.