In response to BIGBROYO
You can do that by defining the icon state within the list itself as well, like so:
var/list/hairstyles = list("Mullet"=list('Mullet.dmi',"icon_state_here"),"Gotenks"=list('Gotenks.dmi',"inserticonstate"))

And change
overlays += hairstyles[hair]

To
var/obj/h = new
//this is looking inside /list/hairstyles for /var/hair and using it's list's first argument, which is it's icon.
h.icon = hairstyles[hair][1]
//The same as above, but this is using it's second argument, which is the icon_state
h.icon_state = hairstyles[hair][2]
overlays += h
Awesome, I worked with the list some to include the layer, pixel x,y, and z. Thanks so much! The last thing I have to figure out is how to delete the current hairstyle so they do not overlap each other when you select a new hairstyle.

-BIGBROYO
EDIT: Changed up the code to demonstrate how I'd go about it
//basically make /obj/hair higher up so that you have more flexibility with it,
//this used to be /obj/h, but was renamed to make it easier to remember
client/var/obj/hair
var/list/hairstyles = list("Mullet"=list('Mullet.dmi',"icon_state_here"),"Gotenks"=list('Gotenks.dmi',"inserticonstate"))

client/verb/change_hair()
var/h = input("Pick a hairstyle","Hairstyle") as null | anything in hairstyles
//make Lummox happy, check if it's null
if(isnull(h)) return
//call our updateHair() proc with the argument of h
updateHair(h)

client/proc/updateHair(new_hair)
//return if the hair isn't defined in our list
if(!hairstyles[new_hair]) return
//if /obj/hair doesn't exist, make it
if(!hair)
hair = new
else
//if not, this means that we have a hair on, in which case, remove it from overlays
overlays -= hair
// same thing as before
hair.icon = hairstyles[new_hair][1];hair.icon_state = hairstyles[new_hair][2]
overlays += hair
//make sure to call updateHair(hair) whenever you change hair, or add it for the first time.
//hair can be either a var that points to hairstyle[hair], as is shown in this example
//or a string of a hairstyle on the list, i.e updateHair("Gotenks")
//I recommend the former.
You should never be setting icon_state on a hair overlay unless you want it to never mirror its root mob's icon_state.
Also, @Lummox: I disagree with the advice you gave. I'll be back in a few hours to address why using separate types for defining overlays is actually a very simple, and arguably good idea, but only for the reasons of BYOND feature gap.
In response to GreatPirateEra
GreatPirateEra wrote:
EDIT: Changed up the code to demonstrate how I'd go about it


Here is what I have from that.

client/var/obj/hair
var/list/hairstyles = list( "Mullet" = list('Mullet.dmi', "Mullet",100), "Gotenks" = list('Gotenks.dmi',"Gotenks",100))


client/verb/style_hair()
var/h = input("Pick a hairstyle","Hairstyle") as null | anything in hairstyles
if(isnull(h)) return
updateHair(h)

client/proc/updateHair(new_hair)
if(!hairstyles[new_hair]) return
if(!hair)
hair = new
else
overlays -= hair
hair.icon = hairstyles[hair][1];hair.icon_state = hairstyles[hair][2];hair.layer = hairstyles[hair][3]
overlays += hair


In both lines where "overlays" is I am getting an undefined var for "overlays" error. Everything else is working great.

-BIGBROYO
Oops. I didn't think this through. Client doesn't have a overlays var. Put it on /mob/player
That fixed the compile error but now when I use the verb in game it says this:

runtime error: cannot read from list
proc name: updateHair (/mob/player/proc/updateHair)
source file: hair.dm,16
usr: (src)
src: Guest-308764653 (/mob/player)
src.loc: the turf (1,1,1) (/turf)
call stack:
Guest-308764653 (/mob/player): updateHair("Mullet")
Guest-308764653 (/mob/player): style hair()

-BIGBROYO
Can you paste the code, exactly as you have it?
mob/player/var/obj/hair
var/list/hairstyles = list( "Mullet" = list('Mullet.dmi', "Mullet",100), "Gotenks" = list('Gotenks.dmi',"Gotenks",100))

mob/player/verb/style_hair()
var/h = input("Pick a hairstyle","Hairstyle") as null | anything in hairstyles
if(isnull(h)) return
updateHair(h)

mob/player/proc/updateHair(new_hair)
if(!hairstyles[new_hair]) return
if(!hair)
hair = new
else
overlays -= hair
hair.icon = hairstyles[hair][1];hair.icon_state = hairstyles[hair][2];hair.layer = hairstyles[hair][3]
overlays += hair



Sorry should have done that in my previous post.

-BIGBROYO
The list of lists should work, but a big question you have to ask is if there's any better way.

Do you need the icon_state in that list? Not really. If that matches the value that was used in input(), then you can just use that value instead. But more to the point, either your hair should be different icons--so that they have all the icon states matching your mob, and can keep in sync when you do stuff like attack and jump and such--or they should simply be states all in one file. It doesn't make sense for your hair to have separate icons and for each one to have just one named icon state.

What I mean is: Say your mob has states like walk, run, dodge, jump. You very likely want the hair icon to have those same states so they'll match up. Having a file called 'mullet.dmi' and giving it only one icon state, called "mullet", doesn't serve that purpose.

So really, all you should need to set is an icon file, not an icon state as well.

Another question is: Do you need the layer in that list? Again the answer is no. Hair is hair, and you should always be giving that the same layer for consistency.
In response to Lummox JR
Lummox JR wrote:
Another question is: Do you need the layer in that list? Again the answer is no. Hair is hair, and you should always be giving that the same layer for consistency.


The layer is just a number I chose, it does not have to be 100, but it does have to be there otherwise the hair obj will appear under the sprite instead of over it.
The layer is just a number I chose, it does not have to be 100, but it does have to be there otherwise the hair obj will appear under the sprite instead of over it.

You should be using FLOAT_LAYER for player overlays, because the player object is likely to change layers very often, and FLOAT_LAYER makes this trivial.
In response to BIGBROYO
BIGBROYO wrote:
Lummox JR wrote:
Another question is: Do you need the layer in that list? Again the answer is no. Hair is hair, and you should always be giving that the same layer for consistency.


The layer is just a number I chose, it does not have to be 100, but it does have to be there otherwise the hair obj will appear under the sprite instead of over it.

If your overlay has FLOAT_LAYER, then it will appear over the sprite.

But what I said specifically was that you don't need a layer number to be set there. That is, you don't need it in that list the way you have it. If you have a type path (or more than one) defined for hair pieces, just make the object of that type, and the overlay will use whatever layer you set for the type.

Right now, you're making this big list of redundant data. When all you need to do is choose an icon, you're choosing an icon_state (which works against your purposes) and a layer as well, and that layer is always the same. Since the layer is always the same, why put it in that list?
That makes sense, set it before the input and it will already have that as default.

But what about this?

runtime error: cannot read from list
proc name: updateHair (/mob/player/proc/updateHair)
source file: hair.dm,16
usr: (src)
src: Guest-308764653 (/mob/player)
src.loc: the turf (1,1,1) (/turf)
call stack:
Guest-308764653 (/mob/player): updateHair("Mullet")
Guest-308764653 (/mob/player): style hair()

EDIT: I indented the hair.overlays here

else
overlays -= hair
hair.icon = hairstyles[hair][1];hair.icon_state = hairstyles[hair][2]
overlays += hair


And now I can select a hairstyle without getting the run time error once, but no hair shows up. If I try to choose a hairstyle a second time, it gives me a run time error.

-BIGBROYO
Best response
This isn't working. You can't simply take code that people suggest, and plug it into your own code blindly and randomly without taking time to digest it and understand what it's supposed to do. Every time someone has offered code, you've tried to shoehorn bits and pieces of it where it doesn't belong. You've done that over and over and over again now. Stop trying to rush to plug code in, and understand it first. Only then will you be able to make it work for you.

In the code you just posted, it's obvious that the hair object is an obj you're using to build an overlay. But that obj is not an item in the hairstyles list, which only has strings as its elements, so hairstyles[hair] will always be null.

When you see code, you need to work out what that code does, what each var is for and how it's used. Once you do that, you'll understand what to do with that code.
To elaborate:
    hair.icon = hairstyles[hair][1];hair.icon_state = hairstyles[hair][2];hair.layer = hairstyles[hair][3]

Replace
hairstyles[hair]

with
hairstyles[new_hair]

I was hoping that you'd take note of this, given that the proc argument
updateHair(new_hair)

takes in this value and the if statement
if(!hairstyles[new_hair]) return

checks for this value as well before proceeding. I'm going to take the blame for this one because I intentionally did those mistakes to try and get you to read over the code before plugging it in but it looks like I've failed.
In response to GreatPirateEra
GreatPirateEra wrote:
I'm going to take the blame for this one because I intentionally did those mistakes to try and get you to read over the code before plugging it in but it looks like I've failed.


Not at all. I appreciate the way you have helped me so much. I know I am just a beginner and still have to learn the ropes, but it means a lot that you'd spend time out of your day to help me in your own way. Maybe next time you could put in your post that you included errors for me to fix, instead of just throwing me something I thought was correct. I type all of the code by hand and I read all of your notes more than once to help make sure I know what I am doing. I fixed the hair layer and the [hair] and everything is working great now. Thanks so much for your help.

-BIGBROYO
In response to BIGBROYO
Maybe next time you could put in your post that you included errors for me to fix, instead of just throwing me something I thought was correct.

Will do.
Page: 1 2