ID:139591
 
Code:
mob
proc
DeleteCharacter()
if(src.client)
alert("WARNING: Your about to select a character to delete.")
var/list/characters=new/list()
var/savefile/F=new("Saves/Index/[copytext(src.ckey,1,2)]/[src.ckey].sav")
F["Characters"]>>characters

var/CancelCharacterDeletion = "Cancel"
var/list/menu = new()
menu += CancelCharacterDeletion
menu += characters


var/result = input("Delete character", "DELETE") in menu

if(result)
characters-=result
F=new("Saves/Index/[copytext(src.ckey,1,2)]/[src.ckey].sav")
F["Characters"]<<characters
if(fexists("Saves/[copytext(ckey(result),1,2)]/[ckey(result)].sav"))
fdel("Saves/[copytext(ckey(result),1,2)]/[ckey(result)].sav")


Problem description:
The deleting of the savefiles in itself works great, however, it won't let me remove the savename from the list of savefiles. the savefile is deleted but the reference is not.

Now what i thought would happen here, is that when i've chosen a save to delete(result), i remove result from characters and then write it back to F["Characters"](hoping that it will overwrite the original content). however it doesn't seem to happen that way, as all references are still there.

Anyone got any clues as to how i might fix this?
I solved the problem, not entierly certain it is an efficient fix, but:
The lines in question
                if(result)
characters -= result
F=new("Saves/Index/[copytext(src.ckey,1,2)]/[src.ckey].sav")
F["Characters"] = null
sleep(1)
F["Characters"]<< characters
if(fexists("Saves/[copytext(ckey(result),1,2)]/[ckey(result)].sav"))
fdel("Saves/[copytext(ckey(result),1,2)]/[ckey(result)].sav")


Not sure the sleep is neccesary.
Likely the issue is that you are attempting to open the savefile before it's been closed, right before rewriting characters. Removing the F=new(...) line will likely solve it.

I will say that maintaining separate files for every single character and then ALSO another file for each player that only serves to LIST the characters is a bit silly, when you can easily store however many characters you want in a single file and also easily grab a list of them via F.dir.
In response to Garthor
I'm not sure i grasp what your describing here, but i'll try and read up on it.

EDIT:
Ah! a quick search and i got it. i'll try redoing it, if it's as easy as it seems there shouldn't be any problems.

EDITx2:

Ah! it really was easy, and neat, having only one file per player. instead of 3 + 1 to keep reference. thanks for the eyeopener.