ID:161108
 
obj
buttons
Save
name="Save/Load"
screen_loc="1,4"
Click()
switch(alert("Would you like so save or load a level?","Save/Load","Save","Load","Cancel"))
if("Save")
var/Sav=input("What would you like to call your level?","Save",usr.lastsaved)as text|null
if(Sav)
var/savefile/F=new("Levels.sav")
F[Sav]<<GetCode()
usr.lastsaved=Sav
usr.levels+="[Sav]"
//for(var/whatever in usr.levels)world<<"[whatever]" <- Nothing is output here!
if("Load")
var/savefile/F=new("Levels.sav")
var/loading=input("Choose a level to load.","Loading")as null|anything in usr.levels
if(loading)LoadCode(F[loading])

I wasn't sure if this was a how-to or a problem, but I'm going to assume that the above code is horrible and wrong (Like always). Anyway, just about the last thing I gotta do before I've finished my game :) is to make a way of saving and loading levels. I thought I could save all a person's levels in one file called Levels.sav, and for every level a person has, there will be a variable in there with that level's name. Thanks to the way I've designed my game, levels can be encrypted into long strings of numbers, so that's not a problem.

The problem is that this doesn't work. After I tried some tests on this piece of code to find out which bits worked... I discovered that nothing seems to be getting added to usr.levels- at least, nothing outputtable. Does anyone have any idea what I'm doing wrong?
Anyone?
I haven't worked much with file handling in DM, but I think it 'd work if you saved users maps in directories with separate files for each map. I'll show what I mean.

Oh, and no usr in procs.

obj/buttons/save/Click()
var/name = input(src,"What do you want to call your map?")
var/mob/M = src //Bit of typecasting to allow us to use the ckey variable
if(fexists("/[M.ckey]/[name].sav")) //It creates a new directory for the user
switch(alert(src,"A file with this name already exists, do you want to overwrite it?","Overwrite?","Yes","No"))
if("Yes")
//write stuff here
else return 0
else
//same write stuff here
In response to Adam753
Please don't bump your message until at least 24 hours have passed and the post is no longer visible on the first page of this forum.

Lummox JR
In response to Darkmag1c1an11
Darkmag1c1an11 wrote:
Oh, and no usr in procs.

Good advice, wrong situation. atom/Click() is a pseudoverb; it is usr-safe as long as client/Click() isn't modified heavily or the proc isn't called manually.

Lummox JR
In response to Darkmag1c1an11
Well, thanks, I didn't know there was an "fexists" proc... but that's not what I mean. I need a way of loading levels, that ISN'T "What's the name of the level you'd like to load".
Originally, I thought I could keep a saved list of all the level names a person had used, so I knew what all of the person's level names were, but that simply refuses to work!
In response to Adam753
Durgh, I know what the problem is now- it's that when I added a text string to a list, it was treating it as a looong text string. For example:
var/list/string[0]
string+="Hi"
string+="Hello"
string+="Apple"
string+="AdamsAwesome"
return(string)
//This was expected to return this:
list("Hi","Hello","Apple","AdamsAwesome")

//instead, it returned this:
"HiHelloAppleAdamsAwesome"

/*So what do you do to create a LIST of strings, rather than a
string? I tried changing this: */

var/list/string[0]
//To this:
var/list/string=list()

//It's now useless. Can't be a list of strings, can't be one text string... Can't be nothin'.


Any ideas?
In response to Adam753
I have no idea why you get that problem, but it works for me:

mob/proc/test()
var/list/string[0]
string+="Hi"
string+="Hello"
string+="Apple"
string+="AdamsAwesome"
return(string)
mob/verb/actual_test()
usr<<test()
In response to DivineO'peanut
Actually... Whatever it was that I changed so that the list was suddenly containing nothing, it was a step in the right direction more me: I've solved it! Yay! I think something was in fact wrong with the loading part. I wish I knew what I'd done, but if anything else goes wrong i'll have to ask you. thanks :)