ID:264978
 
Code:
             switch(input("What is your hair style?") in list ("Long Black","Short Black","Medium Black","Long Red","Short Red","Medium Red","Long Brown","Short Brown","Medium Brown"))


if("Long Black")
usr.overlays+=/mob/Long_Black

if("Short Black")
usr.overlays+=/mob/Short_Black
if("Medium Black")
usr.overlays+=/mob/Med_Black
if("Long Red")
usr.overlays+=/mob/Long_Red
if("Short Red")
usr.overlays+=/mob/Short_Red
if("Medium Red")
usr.overlays+=/mob/Med_Red
if("Long Brown")
usr.overlays+=/mob/Long_Brown
if("Medium Brown")
usr.overlays+=/mob/Med_Brown
if("Short Brown")
usr.overlays+=/mob/Short_Brown


Problem description:

No matter what hairstyle I select,it ends up giving me long red overlays

Well, there's a few big problems here, to start. You shouldn't be using "usr" in procs unless you know exactly what that is referencing. For something like this, "src" is what you would use.

secondly, you don't need to define separate mobs just to add an icon as an overlay, but, if you're doing it for other reasons then may I suggest that you check those mob types to make sure they're using the correct hair types that match with this switch statement.

except for the usr, and the seemingly unnecessary use of custom /mob/ types, the code shown should be okay to use, so make sure to check the the parts of your code to make sure there's no mistakes there.
In response to Bravo1
Bravo1 wrote:
Well, there's a few big problems here, to start. You shouldn't be using "usr" in procs unless you know exactly what that is referencing. For something like this, "src" is what you would use.

I tried using src,nothing different happens

secondly, you don't need to define separate mobs just to add an icon as an overlay, but, if you're doing it for other reasons then may I suggest that you check those mob types to make sure they're using the correct hair types that match with this switch statement.

If i erase the /mob/,I don't get any overlays at all..



In response to Flare SilverBend
using src won't change what happens, but it wont cause problems later. usr can cause issues because it doesn't refer back to the mob who started the proc. usr is not the same as src, and you want to use src for this so that usr doesn't give you issues later.

as for /mob/, you don't have to remove it, go and check where you defined those mobs, and make sure the icons or the icon_states are set properly.
In response to Bravo1
Ive checked them,and I think I might know why its not working now.It might be because all of the overlays are in the same icon file,this has caused problems for me in the past..



mob/Long_Black
icon='Hair.dmi'
icon_state="long_black"
layer=MOB_LAYER+2



mob/Short_Black
icon='Hair.dmi'
icon_state="short_black"
layer=MOB_LAYER+2




mob/Med_Black
icon='Hair.dmi'
icon_state="med_black"
layer=MOB_LAYER+2




mob/Med_Red
icon='Hair.dmi'
icon_state="med_red"
layer=MOB_LAYER+2



mob/Short_Red
icon='Hair.dmi'
icon_state="short_red"
layer=MOB_LAYER+2



mob/Long_Red
icon='Hair.dmi'
icon_state="long_red"
layer=MOB_LAYER+2



mob/Med_Brown
icon='Hair.dmi'
icon_state="med_brown"
layer=MOB_LAYER+2



mob/Short_Brown
icon='Hair.dmi'
icon_state="short_brown"
layer=MOB_LAYER+2



mob/Long_Brown
icon='Hair.dmi'
icon_state="long_brown"
layer=MOB_LAYER+2
In response to Flare SilverBend
Yes, that is true, overlays usually take the icon_state of the mob they are attached to. If you want them to keep their own icon states, you'll need to make an object on the fly.

var/obj/h = new
j.icon='hairs.dmi'
j.icon_state="hairstyle"
overlays+=j

Something liek this will work, but, remember you should reference it in a variable so that you can remove it later

mob/var/hair

var/obj/h = new
j.icon='hairs.dmi'
j.icon_state="hairstyle"
hair=j
overlays+=hair

then if you want to remove it, you can just do:

overlays-=hair
In response to Bravo1
I get a bunch of errors whenever I use the code you wrote..
In response to Bravo1
You can use the image proc to make this even simpler.
e.g.
src.overlays += image('Hair.dmi', "long_red")
In response to Flare SilverBend
Well you can't use the code exactly how it is, you have to replace it with your own icons and icon states and such. It's meant as an example.
In response to Complex Robot
You'd have to output the image to the mob, on top of that, images aren't saved to savefiles, so you'd have to reapply and re-output the hair everytime you login. You'd also have to make sure the entire world is output the same image.
In response to Bravo1
That's not true. When you add an image to an overlay, it's the same as any other object.
It's just a shortcut, and it's better than using the icon() proc and using a dynamic icon operation.

See here.
In response to Complex Robot
Hmmm, I've never seen it used like that. I should modify set_color() in Tanx to do that o__o
In response to Bravo1
Bravo1 wrote:
Well you can't use the code exactly how it is, you have to replace it with your own icons and icon states and such. It's meant as an example.


I know,I still get errors..
In response to Bravo1
On the other hand, that'd be an amazing feature if you could selectively hide overlays from players that easily.
In response to Flare SilverBend
post what you have with the replaced code and I'll see if I fucked it up somewhere (which is likely xD)
In response to Complex Robot
How would I go about adding rgb coloring to the image though?

image(icon+rgb(),yadda,yadda) ??

Would that work?
In response to Bravo1
I don't quite know. I can't find the entry in the reference that says the + operator does the Blend operation. (I think += does.) And you'd have to do a dynamic icon operation anyhow. (You'd have to use the icon proc and then Blend().)
You could still use images to save a little overhead.
I think this might work: (I'll have to test it.)
overlays += image(icon('icon.dmi') + rgb(32, 64, 128))

[EDIT]
No, this doesn't work.
In response to Bravo1
No, that wouldn't work, you can still save an icon operation for choosing the icon state, though.
Like so:
var/icon/I = icon('icon.dmi')
I.Blend(rgb(32, 64, 128))
overlays += image(I, state)
In response to Complex Robot
Actually, it does work. I just tried it out. I'm super surprised.


overlays+=image(icon=base_rgb+rgb(r,g,b),icon_state=base)

That actually works, it does the rgb to the icon and everything. I'm not sure how much it saves on overhead, but it's better than creating an object to add to the overlays, that's for sure.

In response to Bravo1
Wow. I just tried this and I swear it didn't work. Maybe I'll try it exactly the way you did it.
[EDIT]
Wow. Doing 'icon.dmi' + rgb() works, but doing icon('icon.dmi') + rgb() does not work. Maybe that's a BYOND bug.
Page: 1 2