ID:1735022
 
Keywords: cant, color, hair, save, wont
(See the best response by Mightymo.)
Code:
mob/var/Hair = null
mob/var/HairR = null
mob/var/HairG = null
mob/var/HairB = null
mob/var/whichair
mob/var/Eye = null

mob
var
const/HAIR_LAYER = FLOAT_LAYER-3
haircolor
newHair
loadHair
verb
Hairemo1()
if(gnder==1 || gnder==2)
newHair = 'hair_emo.dmi'
newHair += input("Please select your hair color") as color
Hair = newHair
var/Hairred=4
var/Hairgreen=4
var/Hairblue=5
Hair += rgb(Hairred,Hairgreen,Hairblue)
HairR=Hairred
HairG=Hairgreen
HairB=Hairblue
whichair = 1
overlays += Hair

Hairbald()
if(gnder==1 || gnder==2)
usr.overlays -= Hair
usr.Hair = null
whichair = 0

Eyecolor()
if(gnder==1 || gnder==2)
var/newEyes = 'Eye_Overlay.dmi'
newEyes += input("Please select your eye color") as color
Eye = newEyes
var/Eyered=4
var/Eyegreen=4
var/Eyeblue=5
Eye += rgb(Eyered,Eyegreen,Eyeblue)
overlays += Eye
proc
Hairlogin()
var/savefile/F=new("Save/[src.ckey].sav")
Read(F)
F["Hair2"]>>newHair

if(F["Hair"]==0)
usr.overlays -= Hair
usr.Hair = null
whichair = 0
if(F["Hair"]==1)
loadHair = 'hair_emo.dmi'
Hair = loadHair
var/Hairred=4
var/Hairgreen=4
var/Hairblue=5
Hair += rgb(Hairred,Hairgreen,Hairblue)
HairR=Hairred
HairG=Hairgreen
HairB=Hairblue
overlays += Hair
whichair = 1


mob

var/created = FALSE
var/ingame = FALSE

Login()
world << "[key] has just joined the world~"

Logout()
world << "[key] has logged off!"
if(created == TRUE)
if(ingame == TRUE)
var/savefile/F=new("Save/[ckey].sav")
F["Hair"]<<usr.whichair
F["Hair2"]<<usr.newHair
F["Race"]<<usr.race
F["name"]<<usr.name
F["g"]<<src.icon
F["x"]<<src.x
F["y"]<<src.y
F["z"]<<src.z
F["verbs"]<<src.verbs
sleep(2)
Write(F)
sleep(10)
del src
proc
Load()
if(client)
if(fexists("Save/[src.ckey].sav"))
var/savefile/F=new("Save/[src.ckey].sav")
Read(F)
sleep(2)
usr.name = F["name"]
Hairlogin()
icon=F["g"]
if(F["x"]&&F["y"]&&F["z"]) src.Move(locate(F["x"], F["y"], F["z"]))
else src.loc = locate(1,1,1)
if(!isnull(F["verbs"])) src.verbs.Add(F["verbs"])
usr.verbs+=typesof(/mob/verb/)
world << output("~**[key] has returned!**~","TAZgame.oocoutput")
winshow(src, "TAZgame", 1)
winset(src, "charactercreate.map2", "is-default=false")
winset(src, "TAZgame.map1", "is-default=true")
winset(src, "loginwindow", "is-default=false")
winset(src, "TAZgame", "is-default=true")
winshow(src, "loginwindow", 0)
winshow(src, "OptionsWindow", 0)
ingame = TRUE
else
alert("You do not have any characters on this server.")
return


My latest attempt. It works fine saving the hair TYPE but saving color is a whole other issue. I've tried saving the Hairred, etc variables, saving the Hair variable, even saving the newHair variable at seperate instances and reapplying it through the whole process. No errors but it just won't bring back that color when I load in. The last attempt i tried to reapply a seperate variable of 'loadHair' with newHair's colored properties and tried this...

newHair += loadHair as color


but that gave me errors. Any suggestions on an easy way to save the color value so I can reapply it during the HairLoad() proc?
The way I do it uses the text2path proc. This involves having a set of predetermined hair colors, though. Since I like my art consistent I wrote a script that generates all of the hair colors for each hairstyle by running the game with the file included. The main reason is to keep the black outlines, and the result looks like they were recolored by hand. An added benefit is it makes adding hairstyles on Login() really easy.

var/hair = text2path("/obj/Hairstyles/[src.Hairstyle]/[src.HairColor][src.Hairstyle]")
src.overlays += hair


This will ONLY work if your hairstyles and haircolors are hard-coded. Not sure you would want to do this, but it's an option.
I kinda preferred to have it as an option to thoroughly customize hair color. If I wanted to have pre-made colors I have no problem with that. See the icon shows up fine, but getting it to recolor when logging in doesn't work. Thanks for the idea though, I'll keep it in mind, but I'd still prefer to do what I see most rp games (such as the popular naruto-bleach-etc) do where they let you choose a color from the color wheel and it saves it or whatever.
I tried that and it didn't work. I tried saving the individual R G B as three seperate ones, and reapplying. It still came out uncolored.
From what I understand by the time it starts hitting the var/Hairred var/Hairgreen etc it's set newHair to the icon and colored it. But for some reason I can't save this colored icon?
You need to save this value into a variable:
input("Please select your hair color") as color

This is rather than just adding to the icon. Save this string when doing saving. When loading, pull this value and add it to your icon.

When adding, it should not look like
newHair += loadHair as color

The "as color" is unnecessary, as this is not an input.
I tried that... and now I end up with no hair on login.
mob

var/created = FALSE
var/ingame = FALSE

Login()
world << "[key] has just joined the world~"

Logout()
world << "[key] has logged off!"
if(created == TRUE)
if(ingame == TRUE)
var/savefile/F=new("Save/[ckey].sav")
F["Hair"]<<usr.whichair
F["Hair2"]<<usr.haircolor
F["Race"]<<usr.race
F["name"]<<usr.name
F["g"]<<src.icon
F["x"]<<src.x
F["y"]<<src.y
F["z"]<<src.z
F["verbs"]<<src.verbs
sleep(2)
Write(F)
sleep(10)
del src

mob/var/Hair = null
mob/var/HairR = null
mob/var/HairG = null
mob/var/HairB = null
mob/var/whichair
mob/var/Eye = null


mob
var
hairr
hairg
hairb
const/HAIR_LAYER = FLOAT_LAYER-3
haircolor
newHair
loadHair
verb
Hairemo1()
if(gnder==1 || gnder==2)
newHair = 'hair_emo.dmi'
newHair += input("Please select your hair color") as color
haircolor = newHair
Hair = newHair
var/Hairred=4
var/Hairgreen=4
var/Hairblue=5
Hair += rgb(Hairred,Hairgreen,Hairblue)
HairR=Hairred
HairG=Hairgreen
HairB=Hairblue
whichair = 1
overlays += Hair

Hairbald()
if(gnder==1 || gnder==2)
usr.overlays -= Hair
usr.Hair = null
whichair = 0


    proc
Hairlogin()
var/savefile/F=new("Save/[src.ckey].sav")
Read(F)
F["Hair2"]>>haircolor

if(F["Hair"]==0)
usr.overlays -= Hair
usr.Hair = null
whichair = 0
if(F["Hair"]==1)
loadHair = 'hair_emo.dmi'
Hair = loadHair
Hair += haircolor
overlays += Hair
whichair = 1
This is incorrect:
newHair += input("Please select your hair color") as color
haircolor = newHair

You should be saving the color, not the icon.
haircolor = input("Please select your hair color") as color
newHair += haircolor
Still no hair icon at all now on loading
I don't think that has anything to do with the code that I told you to change. What else did you change? I notice that the code under if(F["Hair"]==1) is significantly different, for example.

Also try, running debug statements. Are you certain that that branch is being reached?
mob/var/Hair = null
mob/var/HairR = null
mob/var/HairG = null
mob/var/HairB = null
mob/var/whichair
mob/var/Eye = null


mob
var
hairr
hairg
hairb
const/HAIR_LAYER = FLOAT_LAYER-3
haircolor
newHair
loadHair
verb
Hairemo1()
if(gnder==1 || gnder==2)
newHair = 'hair_emo.dmi'
haircolor = input("Please select your hair color") as color
newHair += haircolor
Hair = newHair
var/Hairred=4
var/Hairgreen=4
var/Hairblue=5
Hair += rgb(Hairred,Hairgreen,Hairblue)
HairR=Hairred
HairG=Hairgreen
HairB=Hairblue
whichair = 1
overlays += Hair

Hairbald()
if(gnder==1 || gnder==2)
usr.overlays -= Hair
usr.Hair = null
whichair = 0

Eyecolor()
if(gnder==1 || gnder==2)
var/newEyes = 'Eye_Overlay.dmi'
newEyes += input("Please select your eye color") as color
Eye = newEyes
var/Eyered=4
var/Eyegreen=4
var/Eyeblue=5
Eye += rgb(Eyered,Eyegreen,Eyeblue)
overlays += Eye
proc
Hairlogin()
var/savefile/F=new("Save/[src.ckey].sav")
Read(F)
F["Hair2"]>>haircolor

if(F["Hair"]==0)
usr.overlays -= Hair
usr.Hair = null
whichair = 0
if(F["Hair"]==1)
loadHair = 'hair_emo.dmi'
loadHair += haircolor
Hair = loadHair
var/Hairred=4
var/Hairgreen=4
var/Hairblue=5
Hair += rgb(Hairred,Hairgreen,Hairblue)
overlays += Hair
whichair = 1


mob

var/created = FALSE
var/ingame = FALSE

Login()
world << "[key] has just joined the world~"

Logout()
world << "[key] has logged off!"
if(created == TRUE)
if(ingame == TRUE)
var/savefile/F=new("Save/[ckey].sav")
F["Hair"]<<usr.whichair
F["Hair2"]<<usr.haircolor
F["Race"]<<usr.race
F["name"]<<usr.name
F["g"]<<src.icon
F["x"]<<src.x
F["y"]<<src.y
F["z"]<<src.z
F["verbs"]<<src.verbs
sleep(2)
Write(F)
sleep(10)
del src
proc
Load()
if(client)
if(fexists("Save/[src.ckey].sav"))
var/savefile/F=new("Save/[src.ckey].sav")
Read(F)
sleep(2)
usr.name = F["name"]
icon=F["g"]
Hairlogin()
if(F["x"]&&F["y"]&&F["z"]) src.Move(locate(F["x"], F["y"], F["z"]))
else src.loc = locate(1,1,1)
if(!isnull(F["verbs"])) src.verbs.Add(F["verbs"])
usr.verbs+=typesof(/mob/verb/)
world << output("~**[key] has returned!**~","TAZgame.oocoutput")
winshow(src, "TAZgame", 1)
winset(src, "charactercreate.map2", "is-default=false")
winset(src, "TAZgame.map1", "is-default=true")
winset(src, "loginwindow", "is-default=false")
winset(src, "TAZgame", "is-default=true")
winshow(src, "loginwindow", 0)
winshow(src, "OptionsWindow", 0)
ingame = TRUE
else
alert("You do not have any characters on this server.")
return


haven't fiddled with anything else, and how do I run debug statements?
Just put something like
world << "Loading hair..."

So that you know an area is reached. Also, you may want to output any relevant values.

I apologize that I cannot comb through your code, but that is a lot to go through. If the hair loading worked before, you may want to consider reverting it to the point where it worked, and then apply the changes that I mentioned.
the changes you made are the point where it stopped working. I don't get why but whenever it tries to apply a color things just flop. And its okay, I'm appreciative that you've even done this much. Also apparently im getting a wierd error during the game when I clicked Load although I didn't notice it before.

runtime error: bad icon operation
proc name: Hairlogin (/mob/proc/Hairlogin)
usr: Darklady5 (/mob)
src: Darklady5 (/mob)
call stack:
Darklady5 (/mob): Hairlogin()
Darklady5 (/mob): Load()
Darklady5 (/mob): gogogo2()
Attempt to debug it then. What happens if you remove the line adding color? If you truly have not changed anything, than this should work again, as the code should be the same as it was before. Also, output the value of haircolor, and see if it is correct. Get the value of any other relevant variables.
sorry could you quote the line you mean I should remove? Just so I don't accidently remove the wrong one? And outputting the value of haircolor during creation gave me "#cc3399" whereas during load gave me nothing. Is there a special way I'm supposed to be saving it instead of the F["Hair2"]<<usr.haircolor ?
You probably don't need to comment that line, as it's pretty clear now where the issue lies; haircolor is null. It may be that you are using usr rather than src, but it doesn't look like that should matter. What is the value of usr.haircolor when you go to save? How about src.haircolor?
save happens automatically when the game closes, but before save the value is that #cc3399 i wrote (or whatever color was chosen during creation). Src didn't seem to change anything, and I still get this error when I click load

runtime error: bad icon operation
proc name: Hairlogin (/mob/proc/Hairlogin)
usr: Darklady5 (/mob)
src: Darklady5 (/mob)
call stack:
Darklady5 (/mob): Hairlogin()
Darklady5 (/mob): Load()
Darklady5 (/mob): gogogo2()
In response to Darklady5
Is that before the save, or during? You should be checking it during; don't assume it will be the same.

That error comes up because haircolor is null. Also, the haircolor is null immediately after loading it, right? Try just outputting F["Hair2"] as well, just in case.
how do I do that? Just world << "F["Hair2"]" ?
Nevermind, I believe I have found the problem. You have opened the same save file twice, you should pass the opened save file to hairlogin instead of opening a new one.
Page: 1 2 3