ID:1845579
 
Hi. What I'm trying to do is make a database for custom perks (obj's admins can create during runtime and give to players. These are clickable and display a PerkDesc to everyone in view. Example: view(10) << "[PerkName]: [PerkDesc]
[PerkNote]
".) But I don't really know how to start. I want each custom perk to be saved in the database with all its vars together. Each custom perk saved would have a name as well (same as the PerkName var), so that admins can also access the PerkDatabase to give out custom perks that were previously created and saved.

((EDIT: The html I typed went through and I don't know how to escape it, so this is what the text of the html looks like:http://i.gyazo.com/eccd20ae1efb2699dccaaf88828f3cba.png ))

What I have now:
proc/SavePerkDatabase()
var/savefile/F=new("AO/PerkDatabase.sav")
F["Perk Name"]<< PerkName
F["Perk Icon"]<< PerkIcon
F["Perk Desc"]<< PerkDesc
F["Perk Type"]<< PerkType
F["Perk Note"]<< PerkNote
F["Perk Requirement"]<< PerkReq


Problem description: But I don't think this would work the way I would want it to. I feel like this format would be good for like.. Saving vars for a time or day cycle system. I'm a beginner so this has got me pretty stumped. Any suggestions or example code that would help?

Well, you could make an actual "perk" object.
obj/perk
/* built-in variables:
name
icon
desc
type
*/


// custom variables:
var
note
requirement


Then, you can save and load a collection of perk instances:
// global variables
var const/PERKS_PATH = "AO/PerkDatabase.sav"
var perks[0] // a list of perk instances

// global procs
proc/save_perks()
var savefile/s = new (PERKS_PATH)
s << perks

proc/load_perks()
if(fexists(PERKS_PATH))
var savefile/s = new (PERKS_PATH)
s >> perks

// e.g.
MyProc()
var obj/perk/my_perk = new
my_perk.name = "Perk Name"
my_perk.icon = 'Perk Icon.dmi'
// etc.
perks += my_perk
save_perks()
Damn that was quick. Thanks Kaiochao, I'll try this out and see how it works.
Hm. Weird. I just finished working on my perk system and I have some errors *sigh*. Here's my work:

The GivePerk() verb where an admin can create a custom perk to give to a player and have the option of saving it to the perk database during runtime
        GivePerk(mob/M in world) //Admin verb
set category = "Admin"
set name = "Give Perk"
var/preicon=null
switch(input("Create a perk, or use one from the database?","Database") in list("Database","Create"))
if("Create")
switch(input("Perks","Does this perk have an icon for it's skillcard?") in list("Yes","No"))
if("Yes")
preicon = input("Perks","Pick an icon for this perk.") as icon //storing perk information in some "temporary" vars
var/preicon_state = input("Perks","Is there a specific icon state in the .dmi file you want this perk to be? If none, place this blank.") as text
var/prename = input("Perks","What is the name of the perk?") as text
var/predescription = input("Perks","What is the perk's description?") as message
var/prenote = input("Perks","Does this perk have a note?") as text
var/precolor = input("Perks","What is the perk's text color? Use xfade's code (example:'#8FBC8F') or text (example:'red')") as text
var/prerequirement = input("Perks","What Echelon is required for someone to use this perk?") as text
if(precolor==null)
precolor="6B6B6B"
if(precolor=="")
precolor="6B6B6B"
if(precolor==" ")
precolor="6B6B6B" //last line of storing perk information during runtime
switch(input("Add to database","Database") in list("Yes","No"))
if("Yes") //if admin wants to save the perk to the database, stores perk's name, icon, description, etc.
var/obj/OO = new/obj/Perk
OO:savedicon=preicon
OO:savedicon_state="[preicon_state]"
OO:savedname="[prename]"
OO:saveddescription="[predescription]"
OO:savednote="[prenote]"
OO:savedrequirement="[prerequirement]"
OO:savedcolor="[precolor]"
PerkDatabase+=OO
SavePerkDatabase()
var/obj/O = new/obj/Perk //if not, the information adminc created during runtime gets stored here and goes into player's contents
O:preseticon=preicon
O:preseticon_state="[preicon_state]"
O:presetname="[prename]"
O:presetdescription="[predescription]"
O:presetnote="[prenote]"
O:presetcolor="[precolor]"
M:contents+=O

for(var/mob/MM in world) if(MM.Admin) MM<< {"<font color=#F88017>[src] just gave [M] [prename] perk."}
Admin_Logs+="<br>[src]([src.key]) gave [M] a perk( [prename] )"
var/gavedate = world.realtime
SaveLogs() //saves admin logs
else
if(isnull(PerkDatabase))
src<<"Database is invalid!"
return
if(!PerkDatabase.len)
src<<"No entries in the database!"
return
var/obj/Perk/P=input("Which perk will you give them?","Database") in PerkDatabase
if(!P) return
if(!istype(P,/obj/Perk)) return
var/obj/Perk/O=copyatom(P)
M:contents+=O
for(var/mob/MM in world) if(MM.Admin) MM<< {"<font color=#F88017>[src] gives [M] [O.name] perk."}
Admin_Logs+="<br>[src]([src.key]) gave [M] a perk( [O.presetname] )"
SaveLogs() //saves what was just added into admin logs



Here's where some vars are defined with the saving/loading proc for the database
/obj/Perk
var
savedname=""
savedicon
savedicon_state=""
saveddescription=""
savedcolor=""
savednote=""
savedrequirement=""

preseticon
preseticon_state
presetname
presetdescription
presetnote=""
presetcolor

// global variables
var const/PERKS_PATH = "AO/PerkDatabase.sav"
var Perk[0] // a list of perk instances

// global procs
proc/SavePerkDatabase()
var savefile/s = new (PERKS_PATH)
s << Perk

proc/LoadPerkDatabase()
if(fexists(PERKS_PATH))
var savefile/s = new (PERKS_PATH)
s >> Perk



I feel like I've overlooked something, but finally, here are the errors I get. Q_Q
Eventmin.dm:271:error: PerkDatabase: undefined var
Eventmin.dm:287:error: PerkDatabase: undefined var
Eventmin.dm:290:error: PerkDatabase.len: undefined var
Eventmin.dm:293:error: PerkDatabase: undefined var



Here's a pic to uh.. You know, helper convenience: http://gyazo.com/bd2c0cdd914b111d62804b529bcdc446 Ignore the little square box with the rgb values at the bottom right; it's a different program.
You haven't defined PerkDatabase
I didn't? Is it not defined in this line of code?
var const/PERKS_PATH = "AO/PerkDatabase.sav"
No no

The variable you're using

if(isnull(PerkDatabase))

if(!PerkDatabase.len)


Isn't defined anywhere.
You're supposed to be adding/removing perk objects from the global list of perks, which you've defined as "Perk". When you want to save the changes to the file (which you might do in world/Del()), you call your SavePerkDatabase().
Hm. So instead I should change this snippet of code to this?

if(isnull(Perk))

if(!Perk.len)