ID:174256
 
For my new Blading game, I wanted a simple loading and saving system. I remembered that I used one a LONG time ago on a Robotz game. So I found my Robotz game, and copied the saving and loading system:

world/mob = /mob/Player  //This makes the default mob to login to a PC.


mob/Player/Login() //Let's get started:
var/I = input("What would you like to do? (You are only allowed one Character per Key, creating a new one will delete the old...)","Logging in:","Continue") in list("Continue","Create New Character") //The input command is made so you can get information from whoever is defined and make the variable defined before the input() that value.
if(I == "Continue") //If the player selected continue...
var/savefile/F = new(client.Import()) //Ok, this is an advanced concept so if you get confused by this, skip it because all you really need to know is the format: savefile is a type like mob, obj, turf, area, atom, and so on are. When you create a new savefile, it is saved in the area specified (in this I do not specify a file path because client.Import does it for me.). client.Import will save it in your \BYOND\users\[Your name here]\Keyinfo\ folder... When I get to client.Export (the second part of this, the actual saving of it in other words) I will explain this some more...
if(F)
F["X"] >> X
F["Y"] >> Y
F["Z"] >> Z
Read(F)
if( X )
src.loc = locate( X, Y, Z )
else
usr << "You don't have a character saved!"
return()
I = "Create New Character" //Turn I back to "Create New Character" so when it gets to that part of the proc below, it will make the person create a new one.
if(I == "Create New Character") //If they selected to create a new character or if it couldn't find a savefile which is defined above...
Name_Character()
mob/proc/Name_Character() //This is a proc we called above in Login().
var/N = input("What would you like your name to be?","Name:",key) as text //The input() proc can also be used to get text form the player, or number, type, or whatever!
if(N == ""||N == null) //If the player did not put anything...
alert("You need to enter a name!") //Tell him this...
spawn() //This is used to make loops that could or do go on forever not crash. You can also put a delay in 1/10s of a second in the arguments to make it wait before calling the proc that is called after it.
Name_Character() //And make him do it again!
else //If the player did enter something...
if(length(N) < 25) //Here is that old length() proc again. This time it checks to make sure the player's name he defined isn't too long.
name = N //Make that mob's name into what the player wanted it to be.
else
//If it is too long...
alert("Your name was too long, it must be below 25 characters!") //Do this stuff again:
spawn()
Name_Character()
usr.loc=locate(2,2,1)

mob/proc/Save_Character() //Ok, now back to the saving stuff. The type of savefiles we are using are unique because they are client-side savefiles, meaning you can login to someone elses server and still have your character.
var/savefile/F = new() //This makes a new savefile. The variable F now means the savefile...
Write(F) //The Write proc, like the Read proc will do savefile saving for you. This however, unlike Read(), will save the players mob that he/she has into the savefile specified.
client.Export(F) //This will put that savefile into your \BYOND\users\[Your name here]\Keyinfo\ folder.
src << "[src.name] saved." //Tell the src that it has been saved.
F["X"] << src.x
F["Y"] << src.y
F["Z"] << src.z

mob/Player/verb/Save() //We gotta let the player do it manually, right?
set category = "Commands"
src.Save_Character() //Save the character with the proc we defined above.

var
X
Y
Z
I


Now creating characters works all fine and dandy, BUT when I continue I jsut get a black screen!

Please help!

~GokuSS4Neo~

P.s. Thank you!
You could check out my sabing with verbs demo if you haven't already.
In response to Airjoe
Wow thanks! Nice and simple! Me like simple! Me like your demo! :P

~GokuSS4Neo~