ID:143459
 
Code:
mob
verb
Hair_color()
var/obj/hair1 = new
var/R = input("How much red to you want in your hair?") as num
var/G = input("How much green to you want in your hair?") as num
var/B = input("How much blue to you want in your hair?") as num
if(R > 255)R=255
if(R < 0)R=0
if(G > 255)G=255
if(G < 0)G=0
if(B > 255)B=255
if(B < 0)B=0
hair1.icon += rgb(R,G,B)
src.overlays = list()
var/obj/hair1/H = new /obj/hair1
src.overlays += H
var/icon/I = new(src.icon)
I.Blend(I,ICON_OVERLAY)
src.icon = I

obj
hair1
icon = 'hair.dmi'
icon_state = "hair1"


Problem description:
When I compile and run, I have no errors or warnings. However, when I use the verb, it successfully adds the overlay and lets me put in the RGB values, but it doesn't actually change the color. Anybody have any ideas? (Sorry if its something obvious, I'm just coming back to BYOND from a 4 year break). Thank you for your time.

Edit: Just found one more bug. The hair isn't overlaying, but under-laying the character icon. :/ Thanks again



Your problem is here:
            src.overlays = list()  // uh?
var/obj/hair1/H = new /obj/hair1 // you're creating a new /obj/hair1 with no changes whatsoever made to it
src.overlays += H // you're adding that object to src's overlays making no use of the actual object that has had his icon modified
var/icon/I = new(src.icon) // now you're just confusing me
I.Blend(I,ICON_OVERLAY)
src.icon = I




This is the code you're looking for:
        change_hair_color(  \
r as num, \
g as num, \
b as num)
r = max(min(r,255),1) // r must be between 255 and 1
g = max(min(g,255),1) // g must be between 255 and 1
b = max(min(b,255),1) // b must be between 255 and 1
var/obj/hair/MyHair = new /obj/hair // create a new /obj/hair
MyHair.icon += rgb(r,g,b) // change his icon according to the rgb value specified\
by usr

overlays += MyHair // give the user of this verb his hair.
In response to DivineO'peanut
Thanks for that, works nicely. Just one question, how would I add description to the window, like "How much red do you want in your hair?" Thanks again.
In response to Zonku
I'm not sure if you can directly include description in the arguments of the verb, so I'd go for using input() to determine the rgb values.