ID:164643
 
I am having some trouble understanding how saving verbs works.

I have it so it gives me a vebr when I double click a certain object but, I don't think it's done so I can save it. I recall trying to fix it awhile ago but, it didn't work as expected so, I'm asking for help on how to save verbs that are given to you by double clicking an object.

What I have so far:

Object code--
obj/grandfireballicon
name = "Grand Fireball Technique: . Techpoint cost: 1"
icon = 'fire element.dmi'
DblClick()
if(usr.techpoints >= 1)
usr.techpoints -= 1
usr << "Grand Fireball Technique chosen"
new/mob/tech/verb/grand_fireball_technique(usr)
else
usr << "Out of tech points!"



I also have this in my save proc-

mob
var
saveverbs
proc
Saveproc()
src.saveverbs=src.verbs
var/savefile/F = new("players/[src.key]/[name].sav")



Thanks in advance for any help.
Why, would you try to save verbs while your trying to save an obj? Look, <font color=red>here</font> and you could find out how to save objs as well.
Well, don't save the verbs themselves. Save a var.
mob
var
specialverbs
Login()
if(usr.specialverbs)
//Do stuff here.
In response to Revojake
At what point would the var represent 20+ verbs that the character may gain over time? Thats the only part I'm having issues with.


Scratch that, I figured it out. I didn't have things in the load proc set up the way I needed them.
In response to Revojake
Using duplicate vars to save built-in vars which aren't saved by default, etc, is a silly idea. You guys should read the DM Guide, especially the savefiles chapter, which covers this.

You can save the verbs list just fine, then load it. The only catch is that you can't directly modify verbs (assign it to a different list or null), you have to use -= and +=.

The way to do stuff such as this is to override the object's Read() and Write() procs to change what happens whenever the object is written and read to/from a savefile.
mob
Write(savefile/F) //override Write() for mobs
..() ////do the default stuff (saving of most vars)
F["verbs"] << src.verbs //save the 'verbs' psuedolist to a new directory in the savefile
Read(savefile/F)
for(var/x in src.verbs) verbs -= x //*empty any current verbs
..() //do the default stuff (loading of most vars)
var/list/L //define a new list
F["verbs"] >> L //and load the saved verbs list into it
for(var/x in L) verbs += x //*then copy it's contents into the 'verbs' list (since we can't just assign it and must use += or Add())



*Note: Instead of for(var/x in src.verbs) verbs -= x, you can just do src.verbs -= src.verbs which just does that loop internally. Same with for(var/x in L) verbs += x, you can do verbs += L.