ID:159277
 
I'm trying to make a game at the moment, nothing to big just something to get out there before I start on a bigger project. However I'm having trouble saving verbs to mobs once they gain them. I just assumed they would be magically saved, this doesn't appear to be the case though! Who would of thunk it? Anyhow, I'm not realy sure how to approach this, the only way I can think of is making a variable like
Has_Awesome_Fireball_Spell = 0

Then whenever they get "Awesome Fireball Spell" set it to one... But I'm not sure if that's the best way to approach things, nor am I sure if it would work.

So, if anyone can help it'd be much appreciated. If not, thanks all the same.
Not exactly what I was looking for, but this seems really helpful and will save me alot of trouble. Thanks. :]
Verbs are NOT automatically saved like the variables. When a mob logs in or is created (via New() ), they will receive the verbs that belong to them and their parents. A mob with the type path /mob/NPC/Enemy will automatically receive (not save...receive) all /mob verbs and /mob/NPC verbs and /mob/NPC/Enemy verbs. However a mob type path of /mob/Player will not automatically receive /mob/NPC or /mob/NPC/Enemy verbs, but only /mob verbs. I hope that clarifies.

If you would like to save verbs (which I highly don't recommend doing) you'll want to create a mimic "verbs" list, and overwrite the Write() and Read() procs.

mob/var/list/mimic_verbs = list()
mob/Write(savefile/s)
for(var/v in verbs) mimic_verbs += v
..()
mob/Read(savefile/s)
..()
for(var/v in mimic_verbs) verbs += v
In response to Spunky_Girl
Spunky_Girl wrote:
Verbs are NOT automatically saved like the variables.

(Or rather, verbs is one of the vars that isn't saved by default, like loc and the coordinate vars)
What you've said is quite correct. When an object is created, all the verbs declared under it (or under its ancestors) are automatically added to its verbs list <small>(and here is the main difference between procs and verbs)</small>, which is of course normal object creation behavior, not saving.

If you would like to save verbs (which I highly don't recommend doing)

Why? I can't see any problem with it at the moment unless you're using client-side savefiles the player could have access to and attempt to edit to add verbs to himself, but then again in that case you need to worry the same for all the saved vars anyway, so it's nothing special. Either way you need to implement a method to prevent savefile tampering.

you'll want to create a mimic "verbs" list

Why, again? The notion of adding useless copy vars that copy some var that isn't saved in order to make it save in themselves is quite a low-level, workaroundish thing to do. You already said to override Read() and Write() to add to the default object saving and loading procedure - then why not save and load the verbs list itself in it?
mob
Write(savefile/F)
..()
F["verbs"] << src.verbs
Read(savefile/F)
..()
var/loaded_verbs
F["verbs"] >> loaded_verbs
src.verbs += loaded_verbs
//you could also do
Read(savefile/F)
..()
src.verbs += F["verbs"]

You can't actually load the verbs list directly to replace the current value of the verbs var though since it's read-only, so you of course add it to the existing list. This keeps any new verbs that may be added to that mob and are not in its savefile; if you wanted the mob to only have the verbs that are stored in the savefile, you'd empty his verbs list before adding to it.
In response to Kaioken
I presume you've read Lummox Jr's "The Pitfalls of Savefiles" article, aye? It's been a while since I last read it but I think Lummox mentions something like an issue where if you run the world, create a player savefile that contains the player's verbs, then edit a verb's type path or delete it altogether, then recompile and run, you'll get a runtime error.

I find it best to just run some kind of checksum-like thing when a player loads to, essentially, reload all their verbs to their character :3

And sorry if my method of saving verbs is newbish. I just haven't done anything to improve my knowledge around savefiles since I don't use them all that much other than to save global vars in their own savefile(s). Then use my described method above for the verb issue.
In response to Spunky_Girl
Spunky_Girl wrote:
create a player savefile that contains the player's verbs, then edit a verb's type path or delete it altogether, then recompile and run, you'll get a runtime error.

It may be possible to actually check if the paths stored in the savefile exist first, but I haven't tried. But sure, if you remove stuff that the savefile expects to be there, you'll get errors. Same thing if you rename or remove any variable of the player, eh? But I think the error is pretty harmless other than showing a runtime error, and would end up being a one-time.

And sorry if my method of saving verbs is newbish.

It's actually a commonly-used method, that people just got kinda used to. That happens often and they just assume the 'popular' implementation is the best or something. :\ There's such an example in the DM Guide, but later in the chapter it also shows how to do it directly.
In response to Kaioken
Yeah to me, one less runtime error means one (or more) less player(s) whining to me about a bug ^-^
In response to Spunky_Girl
Who said the players have to see the runtime errors? :P Hehehe.