ID:139078
 
Code:
mob
icon = 'Player.dmi'

mob
Login()
if(fexists("Saves/[src.ckey]")) // Looks for written save file and if it exists it allows acces to load
var/savefile/S = new("Saves/[src.ckey]") //opens the old save file
Read(S) //Reads it
S["last_x"] >> src.x //Loads the last X Coordinate
S["last_y"] >> src.y //Loads the last Y Coordinate
S["last_z"] >> src.z //Loads the last Z Coordinate
S["icon"] >> src.icon
else
src.loc = locate(86, 125, 1)
..()


mob
proc
Save() //Save procedure
var/savefile/S = new("Saves/[src.ckey]") //Creates a new save of your last saved character
S["last_x"] << src.x //stores last X coordinate
S["last_y"] << src.y //stores last Y coordinate
S["last_z"] << src.z //stores last Z coordinate
S["icon"] << src.icon
Write(S) // Writes the stored files into one

verb //
Save_Player()
src<<"Saving..."
Save()
sleep(10)
src<<"Saved..."


Problem description:
For some reason, when someone saves and then relogs, the icon vanishes and their walking about without an icon.
I would assume that the icon stats no longer match.
I would save the icon name and then call a proc to reassign the icon when you load the mob.


mob
icon = 'Player.dmi'
icon_name="Player"
mob
Login()
if(fexists("Saves/[src.ckey]")) // Looks for written save file and if it exists it allows acces to load
//blah
S["icon"] >> src.icon_name
Load_Icon()

mob
proc
Save() //Save procedure
var/savefile/S = new("Saves/[src.ckey]") //Creates a new save of your last saved character
//blah
S["icon"] << src.icon_name
Write(S) // Writes the stored files into one


Load_Icon()
var/i="[src.icon_name].dmi"
src.icon=i

In response to Rapmaster
...what?
I don't know your experience with icons, so I will simply assume that you don't know much of what you're working with.

what you should try to do is something like the following
mob
icon = 'Player.dmi'
icon_state="Player" //changed it cause I'm more comfy with icon_state
mob
Login()
if(fexists("Saves/[src.ckey]"))
S["icon"] >> src.icon
S["icon_state"] >> src.icon_state
Load_Icon()

mob
proc
Save()
var/savefile/S = new("Saves/[src.ckey]")
S["icon"] << src.icon
S["icon_state"] << src.icon_state
Write(S)

All I'm pointing out is that icon and icon_state are necessary. Loading one without the other can be chaotic unless you know what you're doing...
actually your save system in general seems lacking but that's beside the point. I would simply suggest going to look up blogs about save systems...

Another thing, just to let you know...
       Load_Icon()
var/i="[src.icon_name].dmi"
src.icon=i


That part seems a little...redundant...and...other words. You have created a text variable, and expect to load it as a file? (by the way, that's the difference between using " and ')
I'm sorry buddy, I don't think it works that way at all...
[link]

Also, you should not be calling Read() or Write() directly.

You are not removing the icon data in the savefile as well, if you're attempting to do so, you do it this way:

Write( savefile/savefile )

..()

savefile.dir.Remove( "icon" )


To Rapmaster:

Recheck your provided snippet, in your <small>Login()</small> snippet, you're missing the default procedure call and this could harvest more problems with the Login system.
In response to Katsuri
You are right about that piece of code, it is terrible.

However, when a mob is assigned to a new icon without an icon_state it automatically leads to the "" state?(by the way it is normally blank and not "" in the .dmi file). Most pixel artists i work with have adopted this as the default state so i guess its whatever works huh.

P.S: Thank you for explaining the difference between " and ', apparently i did not know the difference.