ID:175133
 
sorry for posting thnis twice but i really need help on this i have spent 2 months i just this one question. How do i make my saveing code save the location?

here is my code:

mob
proc
Save_Character()
var
savefile/F = new()
saved_x ***
saved_y ***
saved_z ***
Write(F)
saved_x = x
saved_y = y
saved_z = z
client.Export(F)
src << "[src.name] saved."
mob/PC/verb/Save()
set category = "Communication"
src.Save_Character()


*** = warning or error
The Adventures of Perspolis.dm:439:saved_x :warning: variable defined but not used
The Adventures of Perspolis.dm:440:saved_y :warning: variable defined but not used
The Adventures of Perspolis.dm:441:saved_z :warning: variable defined but not used
Sigh, I suppose everyone was hoping you'd figure out that your Write proc override didn't belong in your save code :/

mob
var
saved_x
saved_y
saved_z
proc
Save_Character()
var
savefile/F = new()
Write(F)
client.Export(F)
src << "[src.name] saved."
mob/PC/verb/Save()
set category = "Communication"
src.Save_Character()

mob/Write(savefile/F)
saved_x = x
saved_y = y
saved_z = z
..()
In response to Jon88
lol, im sorry but i get a

The Adventures of Perspolis.dm:450:error:Write :duplicate definition (conflicts with built-in proc)
In response to Nave
Sorry, I fixed it in my earlier post.
In response to Jon88
yeah i actually figured out the problem for my self but it still doesnt work
In response to Nave
i think maybe i have the whole thing wrong
In response to Nave
Here's a snippet from my current project:

<code>mob/person/player Read(savefile/F) .=..() var {last_x;last_y;last_z} F["last_x"] >> last_x F["last_y"] >> last_y F["last_z"] >> last_z var/newloc=locate(last_x,last_y,last_z) if (!Move(newloc)) world.log << "[src] failed to move to [last_x],[last_y],[last_z]" loc=newloc Write(savefile/F) .=..() F["last_x"] << x F["last_y"] << y F["last_z"] << z</code>

That automatically loads and saves the mob's position when the mob is loaded and saved, using last_x, last_y and last_y vars. You'll need to adjust those var references to fit in with the vars you have defined.

Using the above code, you can just save the mob itself and not worry about the position.
In response to Crispy
im confused
In response to Nave
maybe its something in a different place in my code, like right here in the login part:



mob/PC/Login()           //Let's get started:
var/I = input("What would you like to do?","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) //If there was a file there...
Read(F) //Read the mob specified in the file. The Read() proc reads all vars in the mob in the savefile (tmp vars are not saved, which I will show you a little later in the grouping procedures section.).
else
usr << "You don't have a character saved!"
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() //Call this proc which is defined below the Login() proc. This is the same as calling src.Name_Character().
var/C = input("What would you like your character to be?","Class:") in list("female Warrior with pike","Wizard","Male Knight") //Ditto but with class.
if(C == "female Warrior with pike") //Now, to set stats... Because I defined icon_state in a special way above, I wont need to do anymore defining of it.
icon = 'warrior_f1.dmi'
Min_Damage = 1 //A warrior's stats:
Max_Damage = 3
Attack_Delay = 4
HP = 30
MAX_HP = 30
MP = 10
MAX_MP = 10
Strength = 2
Defense = 2
AGI = 3
DEX = 4
EXP_To_Next = 100
if(C == "Male Knight")
icon = 'knight_m4.dmi'
Min_Damage = 1 //A wizard's stats:
Max_Damage = 3
Attack_Delay = 4
HP = 25
MAX_HP = 25
MP = 20
MAX_MP = 20
Strength = 1
Defense = 1
AGI = 2
DEX = 3
EXP_To_Next = 100
if(C == "Wizard")
icon = 'wizard.dmi'
Min_Damage = 1 //A wizard's stats:
Max_Damage = 3
Attack_Delay = 4
HP = 25
MAX_HP = 25
MP = 20
MAX_MP = 20
Strength = 1
Defense = 1
AGI = 2
DEX = 3
EXP_To_Next = 100
loc = locate(102,93,1) //Puts the player at the starting position.

..() //This will call another Login() proc if it is defined somewhere... Which it is down above grouping which we will get to later.

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!") //Do this stuff again:
spawn()
Name_Character()
mob
var
saved_x
saved_y
saved_z
proc
Save_Character()
var
savefile/F = new()
Write(F)
client.Export(F)
src << "[src.name] saved."
mob/PC/verb/Save()
set category = "Communication"
src.Save_Character()

mob/Write(savefile/F)
saved_x = x
saved_y = y
saved_z = z
..()
In response to Nave
I am still stumped
In response to Nave
Your problem is that your saving is probably working PERFECTLY. However, you aren't loading the savefiles, and if you were, without making your own Read() proc like you did for the Write() one, the mob's locations won't be set.