ID:2175568
 
Code:
//Selecting what slot to load
proc/Dunglasloading()
var
global/current_file
slot_list = list("Slot 1","Slot 2","Slot 3")
default_value = "Slot 1"
loaded_slot = input("Load game","What slot would you like to load?",default_value) in slot_list
switch(loaded_slot)
if("Slot 1")
usr << "Loading slot 1..."
current_file = 1
src.NewChar()
if("Slot 2")
usr << "Loading slot 2..."
current_file = 2
src.NewChar()
if("Slot 3")
usr << "Loading slot 3..."
current_file = 3
src.NewChar()
else
Dunglasloading()

//Saving the char in the right slot
Logout()
world <<"[src.ckey] has left Dunglas."
var
subfolder = copytext(usr.ckey,1,2)
savefile/F
switch(current_file) //this is the problem: var doesn't carry over from another proc
if("Slot 1") F = new("savefiles/[subfolder]/[usr.ckey]/1")
if("Slot 2") F = new("savefiles/[subfolder]/[usr.ckey]/2")
if("Slot 3") F = new("savefiles/[subfolder]/[usr.ckey]/3")
Write(F)
F["saved_x"] << usr.x
F["saved_y"] << usr.y
F["saved_z"] << usr.z
del(src)
..()


Problem description:

I am making a savefile system that consists of 3 different slots, each having its own savefile. However, I am having trouble with the variable that determines which slot is currently being played on (current_file), that is first determined on login, once the Dunglasloading proc is triggered.
The problem is that the variable current_file isn't recognized in the logout proc, which is normally used to tell the game what slot to overwrite. I turned the variable global in hopes it would help but it didn't do the job.
"global" local variables (variables declared in procs with the "global" keyword) only exist in the proc it's declared in, but are persistent between all calls of the proc.

What you probably want instead is a client or mob variable. Here's an example of a client variable being used:
client
// 1, 2, or 3
var current_slot

    proc/Dunglasloading()
var
list/slot_list = list("Slot 1", "Slot 2", "Slot 3")
default_value = "Slot 1"

// 1, 2, or 3
loaded_slot = slot_list.Find(input(src,
"Load game", "What slot would you like to load?",
default_value) in slot_list)

src << "Loading slot [loaded_slot]..."
client.current_slot = loaded_slot
NewChar()

    Logout()
world <<"[ckey] has left Dunglas."
var
subfolder = copytext(ckey, 1, 2)
savefile/F = new ("savefiles/[subfolder]/[ckey]/[client.current_slot]")
Write(F)
F["saved_x"] << x
F["saved_y"] << y
F["saved_z"] << z
del(src) // <-- reconsider
..()

You need to get usr out of your procs. It doesn't belong there.
Sorry, a bad habit. Just rewrote most of the code to have usr out of it.
I tried your script, Kaiochao, and did some adaptation. There are 3 errors still showing up though that I can't seem to get out of it. I'll just paste the whole thing here:
mob
//1, 2, or 3

var current_slot

Login()
world << "[ckey] has joined Dunglas."
loc = locate(251,211,1)
..()
Dunglasloading()

//Selecting what slot to load
proc/Dunglasloading()
var
slot_list = list("Slot 1","Slot 2","Slot 3")
default_value = "Slot 1"

//1, 2, or 3
loaded_slot = slot_list.Find(input(src,"Load game","What slot would you like to load?",default_value) in slot_list)

src << "Loading slot [loaded_slot]..."
current_slot = loaded_slot

//Does said savefile exist in said slot?
var
subfolder = copytext(ckey,1,2)
savefile/F = new("savefiles/[subfolder]/[ckey]/[current_slot]")
if(fexists(F))
src << "Data found."
LoadSlot()
else
src << "No data found."
NewChar()

    Logout()
world <<"[ckey] has left Dunglas."
var
subfolder = copytext(ckey,1,2)
savefile/F = new("savefiles/[subfolder]/[ckey]/[current_slot]")
Write(F)
F["saved_x"] << x
F["saved_y"] << y
F["saved_z"] << z
..()


Errors:
scripts\login.dm:19:error: slot_list.Find: undefined proc

It doesn't take the current_slot for some reason and has problems with slot_list.Find too for some reason. Sorry for the annoyance guys, I'm pretty new to dm coding, but I'm trying to get better slowly.
In response to Kayren
Oops, I forgot to declare the variable "slot_list" as a list type. It goes like this:
// compiler error: slot_list isn't declared as a type that has a Find() proc
var slot_list = list(...)
slot_list.Find(...)

// no compiler error: slot_list is declared as a /list, which has a Find() proc
var list/slot_list = list(...)
slot_list.Find(...)

// no compiler error, but runtime error (if /mob doesn't have a Find() proc defined):
var list/slot_list = new /mob
slot_list.Find(...)

I edited my previous post with the fix.

I suggested that you use a client variable because it definitely wouldn't be possible to overwrite it when loading a mob.

I also said a mob variable would work, but I forgot to mention that it would need... special attention. Depending on how your LoadSlot() proc works, it's possible that the current_slot value is being overwritten. One solution might be to declare current_slot as a tmp var, which means that it is not saved or loaded by Write() and Read().
mob
var tmp/current_slot
IMO, the slot system is not such a great idea. If you do have slots, keep them in the savefile itself. This avoids the need to have a dir for each player, when you could simply have one single file.