ID:145428
 
Code:
mob
barber
DblClick()
if(!(src in oview(1))) return 0
switch(input("What hair style would you like me to do for you today?")in list("Bald", "Gaara - 10", "Chouji - 10", "Nothing"))
if("Bald")
usr.removehair()
usr.removehair()
if("Gaara - 10")
if(usr.Yen >= 10)
usr.Yen -= 10
usr.removehair()
var/obj/hairs/GaaraHair/a=/obj/hairs/GaaraHair
usr.crgb(a)

mob/proc/crgb(obj/a)
var/r=input(src,"How much red should the hair have? Between 0 and 255!") as num
var/g=input(src,"How much green should the hair have? Between 0 and 255!") as num
var/b=input(src,"How much blue should the hair have? Between 0 and 255!") 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
a.icon+=rgb(r,g,b)
src.Overlays+=a
src.update()


Problem description: Runtime error that it can't read /obj/hairs/'whateverhairIpicked'.icon
This sounds quite obvious, but I have no clue how to fix it. As you can see, I'm using 'Overlays' instead of 'overlays', being it that it's handyer and doensn't mess up overlays.
Any thoughts?

You can use min() and max() for that.


r = min(max(0,r),255)
...etc
In response to Papoose
Euh, that's nice, but doesn't quite solve me problem :/
mob
barber
DblClick()
if(!(src in oview(1))) return 0
switch(input("What hair style would you like me to do for you today?")in list("Bald", "Gaara - 10", "Chouji - 10", "Nothing"))
if("Bald")
usr.removehair()
usr.removehair()
if("Gaara - 10")
if(usr.Yen >= 10)
usr.Yen -= 10
usr.removehair()
var/obj/hairs/GaaraHair/a=new // you have to create the object in order to modify its icon :P
usr.crgb(a)

In response to Nintendo
I did that, but that way I seem to be unable to remove it from the Overlays list...
In response to Mysame
Mysame wrote:
I did that, but that way I seem to be unable to remove it from the Overlays list...

When you add an object to overlays (not Overlays, BTW), only a copy of it is added to the list. To access that copy so you can remove it later, just set a var to the value of overlays[overlays.len] after you've added the obj to the list.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
set a var to the value of overlays[overlays.len] after you've >added the obj to the list.

Wait, so I should also figure in what position the object is added in? o.o;
I'm quite confused here >.<
In response to Mysame
It is getting added to the end, so overlays.len would be the position it was added into.
In response to Papoose
Ahh, true. Forget about that, lemme try.

EDIT: Unnnggghhhhh. It works like a charm when added to 'overlays', there's just that minor drawback of 'overlays' resetting to 0 when update() is called... And adding to Overlays doesn't work, strangely enough..
In response to Mysame
Mysame wrote:
Ahh, true. Forget about that, lemme try.

EDIT: Unnnggghhhhh. It works like a charm when added to 'overlays', there's just that minor drawback of 'overlays' resetting to 0 when update() is called...

Then don't reset it in update().

And adding to Overlays doesn't work, strangely enough..

Maybe because there's no such var.

Lummox JR
In response to Lummox JR
Well, it is defined mob/var/list/Overlays ... :|
Any advice here? Even adding usr.Overlays-='whateversuit.dmi' a dozen times doesn't help. Isn't there any way I could add the hair to Overlays?

EDIT:
mob
var/list/Overlays=list()
proc/update()
src.overlays=null
for(var/i in src.Overlays)src.overlays+=i
mob
barber
icon='npcs.dmi'
icon_state="woman2"
layer=8
density=1
npc=1
DblClick()
if(!(src in oview(1))) return 0
switch(input("What hair style would you like me to do for you today?")in list("Bald", "Gaara - 10", "Chouji - 10", "Nothing"))
if("Bald")
usr.removehair()
if("Gaara - 10")
if(usr.Yen >= 10)
usr.Yen -= 10
usr.removehair()
//var/obj/hairs/GaaraHair/a=new
var/icon/i=new('hair_gaara.dmi')
usr.hairaddress=i
usr.crgb(i)
else usr<<"You do not have enough money!"
if("Chouji - 10")
if(usr.Yen >= 10)
usr.Yen -= 10
usr.removehair()
//var/obj/hairs/ChoujiHair/a=new
var/icon/i=new('hair_choji.dmi')
usr.hairaddress=i
usr.crgb(i)
else usr<<"You do not have enough money!"
mob/proc/crgb(icon/a)
var/r=input(src,"How much red should the hair have? Between 0 and 255!") as num
var/g=input(src,"How much green should the hair have? Between 0 and 255!") as num
var/b=input(src,"How much blue should the hair have? Between 0 and 255!") 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
a.icon+=rgb(r,g,b)
src.Overlays+=a
src.update()
mob/proc/removehair()
src.overlays.Remove(src.hairaddress)
src.update()
mob/var/hairaddress
In response to Mysame
Mysame wrote:
Well, it is defined mob/var/list/Overlays ... :|

Dude, why would you create a var with the same name except for capitalization? There's a sure way to screw up your code.

Ditch that list and use what else you learned in this thread to write code that makes sense.

Lummox JR