ID:262227
 
Code:
proc/AddColor(Color)
var/mob/Login_Mob/Pick_Char/P=usr
for(var/obj/hair/O in P.client.screen)
switch(Color)
if("red") O.icon += rgb(255,0,0)
if("brown") O.icon += rgb(153,102,0)
if("black") O.icon += rgb(17,17,17)
if("blue") O.icon += rgb(0,0,255)
if("green") O.icon += rgb(0,255,0)
if("pink") O.icon += rgb(255,100,150)
if("white") O.icon += rgb(225,225,225)
if("grey") O.icon += rgb(204,204,204)
if("yellow") O.icon += rgb(255,255,0)


Problem description:
Well, I'm sure this snippet should add the 'Color' to the player's hair which is 'O' and of course the player is 'P'.
Ryne Rekab wrote:
Problem description:
Well, I'm sure this snippet should add the 'Color' to the player's hair which is 'O' and of course the player is 'P'.

Well, first of all, the type casting doesn't change a thing: you're still abusing usr in proc.

Second, you aren't allowed to search through client screen like this:

for(var/obj/hair/O in P.client.screen)


If you want to be able to reference the hair, then store it in a list.
In response to Wizkidd0123
Wizkidd0123 wrote:
Well, first of all, the type casting doesn't change a thing: you're still abusing usr in proc.

obj
Hair_Color
Red
icon='Hair_Color_Code.dmi'
icon_state="red"
screen_loc="3,10"
Click()
AddColor("red")


From this I did...

var/mob/Login_Mob/Pick_Char/P=usr


Maybe I should change it to something like.

obj
Hair_Color
Red
icon='Hair_Color_Code.dmi'
icon_state="red"
screen_loc="3,10"
Click()
AddColor("red",usr)
proc/AddColor(Color,Player)
var/mob/Login_Mob/Pick_Char/P=Player


Yes, no, maybe?

Second, you aren't allowed to search through client screen like this:

for(var/obj/hair/O in P.client.screen)


Well, you can. I know you can, there is a couple more of these through my stupid character login set-up.
In response to Ryne Rekab
Ryne Rekab wrote:
Maybe I should change it to something like.

> obj
> Hair_Color
> Red
> icon='Hair_Color_Code.dmi'
> icon_state="red"
> screen_loc="3,10"
> Click()
> AddColor("red",usr)
> proc/AddColor(Color,Player)
> var/mob/Login_Mob/Pick_Char/P=Player
>

Yes, no, maybe?

Instead of passing usr through as an argument, why not just define AddColor() under mob/Login_Mob/Pick_Char instead? That way, you culd just use src and not have to worry about passing an extra argument through! =)

Second, you aren't allowed to search through client screen like this:

for(var/obj/hair/O in P.client.screen)

Well, you can. I know you can, there is a couple more of these through my stupid character login set-up.

My mistake. For some reason, in my head, I decided that you weren't manually adding O to client.screen in the first place. Now that I see that you'er using screen_loc, I realize that you are. Nevermind. =P
In response to Wizkidd0123
Thanks for the help. It would of probably been faster if we just did this in Chatters, eh? Well, to heck with it, we'll just waste some BYOND bandwidth. ^_-

-Ryan
In response to Ryne Rekab
Eh, well crap. It isn't working I did what you said I turned it into /mob/login_blahblah and all, but it still doesn't turn into the colour.
            AddColor(Color)
for(var/obj/hair/O in src.client.screen)
switch(Color)
if("red") O.icon += rgb(255,0,0)
if("brown") O.icon += rgb(153,102,0)
if("black") O.icon += rgb(17,17,17)
if("blue") O.icon += rgb(0,0,255)
if("green") O.icon += rgb(0,255,0)
if("pink") O.icon += rgb(255,100,150)
if("white") O.icon += rgb(225,225,225)
if("grey") O.icon += rgb(204,204,204)
if("yellow") O.icon += rgb(255,255,0)
/////////////////
Hair_Color
Red
icon='Hair_Color_Code.dmi'
icon_state="red"
screen_loc="3,10"
Click()
var/mob/Login_Mob/Pick_Char/P=usr
P.AddColor("red")
In response to Ryne Rekab
            AddColor(Color)
for(var/obj/hair/O in src.client.screen)
switch(Color)
if("red") O.icon += rgb(255,0,0)
if("brown") O.icon += rgb(153,102,0)
if("black") O.icon += rgb(17,17,17)
if("blue") O.icon += rgb(0,0,255)
if("green") O.icon += rgb(0,255,0)
if("pink") O.icon += rgb(255,100,150)
if("white") O.icon += rgb(225,225,225)
if("grey") O.icon += rgb(204,204,204)
if("yellow") O.icon += rgb(255,255,0)
/////////////////
Hair_Color
Red
icon='Hair_Color_Code.dmi'
icon_state="red"
screen_loc="3,10"
Click()
var/mob/Login_Mob/Pick_Char/P=usr
P.AddColor("red")

Well, first of all you really don't need to type cast in the Click() proc:

            Click()
usr.AddColor("red")


That won't solve anything, but I thought it was worth the telling.

Anyway, I think that it's a pretty big design flaw to have a seperate type for each different hair color. Instead, since the only difference is the icon_state, you should be able to easily make a proc to take care of that. Also, AddColor() should take a hex value. Remember, since rgb() is really just a dec2hex() proc, and anything that expects an rgb() is, in reality, expecting hexidecimal, you could just do this:

            AddColor(color)
for(var/obj/hair/O in src.client.screen)
O.icon += color


Finally, I'm still not quite sure that O exists. Try this to make sure:

            AddColor(color)
for(var/obj/hair/O in src.client.screen)
world << "O: [O]"
O.icon += color
In response to Wizkidd0123
Wizkidd0123 wrote:
>     Hair_Color
> Red
> icon='Hair_Color_Code.dmi'
> icon_state="red"
> screen_loc="3,10"
> Click()
> var/mob/Login_Mob/Pick_Char/P=usr
> P.AddColor("red")
>

Well, first of all you really don't need to type cast in the Click() proc:

>             Click()
> usr.AddColor("red")
>


Wiz, this just doesn't work. I've tried to do it, but since AddColor is now a proc of /mob/Login_Mob/Pick_Char/ it gives me an error:

Login.dm:402:error:usr.AddColor:undefined proc
In response to Ryne Rekab
Ryne Rekab wrote:
Wiz, this just doesn't work. I've tried to do it, but since AddColor is now a proc of /mob/Login_Mob/Pick_Char/ it gives me an error:

Login.dm:402:error:usr.AddColor:undefined proc

I need to think before I hit the post button. I was even the one who told you to define AddColor() under all of that: Doh! Still, the second piece of advice holds true. Add the debug message to AddColor(), and have it take a hex value.