ID:100151
 
Keywords: datum, names
Another post!

/*
Usage:
Initializer (REQUIRED): var/names/n = new/names

Adding: n.add(name) -> [ TRUE | FALSE ]
Removing: n.rem(name) -> [ TRUE | FALSE ]
File Existence: n.load() -> [ TRUE | FALSE ]
Exporting Names: n.load(1) -> [ /list ]

*/

names
var/namefile = "savefile/system/names.sav"

proc/load(export=0)
if(fexists(namefile))
switch(export)
if(1)
var{namelist[];savefile/F = new(namefile)}
F["n"] >> namelist
. = namelist
else .=1
else .=0

proc/add(name)
var/namelist[] = list()
if(load()) namelist = load(1)
if(name in namelist) return 0
namelist+=name
var/savefile/F = new(namefile)
F["n"]<<namelist
.=1

proc/rem(name)
var/namelist[] = list()
if(load()) namelist = load(1)
if(!(name in namelist)) return 0
namelist-=name
var/savefile/F = new(namefile)
F["n"]<<namelist
.=1

Note: There is no play-by play one what is done in the code, I'm not a good explainer. The usage (how to use) is at the top.
Nice.
I have no idea what you're on about, is that supposed to be a player name database? You should really add functionality to check if a name is already in the database without adding it.
Toadfish wrote:
I have no idea what you're on about, is that supposed to be a player name database? You should really add functionality to check if a name is already in the database without adding it.

proc/check(name)//returns false if not found, true if found
.=0
var/namelist[]=list()
if(load()) namelist=load(1)
if(name in namelist) return 1


Although technically you could use add or remove to check if a name is in the list, you would have to call the opposite function in some cases (such as if it wasn't in the list in add() or if it was in the list in rem()) to restore the list to it's original form.
it would seem more appropriate to cache the contents of the savefile in a list, to avoid the constant reading just to check for duplicates.
I did it like that so there wouldn't have to be any extra lists stored in memory. But You're right on how it would avoid repeating a lot of things over and over again.