ID:1515678
 
(See the best response by JEY_SENSEY.)
Code:mob/barber
icon='Barber.dmi'
name="Barber"

mob/barber/verb
Haircut()
set src in view(1)
switch(input("Would you like a haircut?")in list("Yes","No"))
if("Yes")
switch(input in list("Afro"))
if("Afro")
set overlays+='afro.dmi'




obj/Hair
Afro
icon='afro.dmi'



Problem description:Cant seem to make a working barber code,have tried many things,the code i used is just one of the many i tried,plz help me a little here

1-should place the code within the code (<)dm(>) code (<)/dm>(/) {whitouts ()}

2- who wants to make a verb that can change someone's hair or an npc that will interact with the hair change someone?

if npcs is a need to put a proc interaction can be Click() or Dblclick()
Your problem lies within the line:
switch(input in list("Afro"))


See if you can see what you did wrong here.
In response to JEY_SENSEY
JEY_SENSEY wrote:
1-should place the code within the code (<)dm(>) code (<)/dm>(/) {whitouts ()}

2- who wants to make a verb that can change someone's hair or an npc that will interact with the hair change someone?

Not really helping if you're judging him on a NPC he wants to have in his game.
In response to Howey

I was editing my post to be more specific ¬ ¬
Best response
ok check this out Jordan35 what I did was to use a DblClick() to to interact with the npcs:
mob/barber
icon = 'Barber.dmi'//examples
icon_state="Barber"//examples
DblClick()//here
if(src in oview(1))
switch(alert("cut??","barber","yes","no"))
if("yes")
usr.overlays-=usr.hair
switch(alert("Would you like a haircut?","barber","yes","no"))
if("yes")
switch(input("type?", text) in list ("Afro","Bald"))
if("Bald")
usr.hair = "Bald"
usr.hairselected=1
return
if("Afro")
usr.hair = "Afro"
var/hairover = 'afro.dmi'
usr.Haircolor(hairover)
return

and use some variables and a one proc() to select the color of your hair
mob
var
hair
hairselected=0
hairred
rhair
Ohair
hairover

mob/proc/Haircolor(hairover)//proc for select color hair
var/hairred = input("what color?") as color
hairover += hairred
usr.rhair = hairred
usr.Ohair = hairover
usr.hair = usr.Ohair
usr.overlays += usr.hair
usr.hairselected=1

Greetings, jey sensey
In response to JEY_SENSEY
JEY_SENSEY, I think you need to take some time to learn good code concepts. You have posted many bad examples that really complete simple concepts recently.


Always increase Re-usability, and decrease Redundancy.
Use Encapsulation, the language is built for it.
Become Organized with you code, and use the most efficient methods to get the job done.
Remove code that adds no meaning.
Finally, learn the concepts of the language. You abuse usr far to much to prove you know how the language works.

In response to Pirion
okey thanks so much...
apparently not enough to help, you have to be perfect, nobody is,neither are their codes pirion,is the last time I help in this way bye bye...
He gave you good advice. Basically imagine the steps it would take to add more hair selections to your code and decrease them.
That code can be improved a lot though - Pirion is trying to help him as well as you; no one here is bashing and he shouldn't be offended.

That's 6 vars under mob, two of which I don't see actually used, 5 of them don't need to exist. He uses an alert for bald and afro which should be an input. There's a bit of needless switching going on. Overall it looks like bit and pieces of two different methods.

mob/barber
//icon = 'Barber.dmi'
//icon_state="Barber"

DblClick()
..()

if(get_dist(src,usr)>1) return//more efficient than range()/view()
//Avoid heavy/unnecessary indenting to help readability

if(alert(usr,"Hello [usr], want your hair changed?","[src]","Yes","No")=="Yes")

var/hair_state = input(usr,"What style would you like?","[src]") as anything in Hairs+list("Bald")
if(!hair_state) return

usr.overlays -= usr.hair
usr.hair = image('Hair.dmi',hair_state,layer=MOB_LAYER+0.01)
usr.hair.name = hair_state
//this stores the icon_state in a niffty way for later use

//Hair.dmi should be an icon where all your hair states are in
//hair_state = the hair's icon_state
//layer should be what ever your mob is +0.01 so the hair is really close to it's layering

if(hair_state!="Bald")//make sure to include a blank "bald" state in the dmi
var/hair_color = input(usr,"What color would you like?","[src]",usr.hair.color) as color
if(hair_color) usr.hair.color = hair_color

usr.overlays += usr.hair

mob/proc/ColorHair(color)//just color not style change
if(!hair) return
overlays -= hair
hair = image('Hair.dmi',hair.name,layer=MOB_LAYER+0.01)
hair.color = color
overlays += hair

mob/var/image/hair = null
var/list/Hairs = list("Afro")


Now for cool stuff.

If you do not want to set the states personally, and make it so you just have to add new icon states into the dmi to add more hairs to the game, use:
var/list/Hairs = icon_states('Hair.dmi')


Note: for the icon_states() method the current example expects the Hair.dmi to only contain hair states. If you want hair states to be mixed with other states you're going to have to make a proc to filter the icon_states.

The above example also makes use of the color var and that only works with white icons.
well it seems that the code doesnt work,but i really thank jey_sensey for his help,and i dont want to bash anyone and thanks for help,will try to figure this on my own
Jittai ty
My code?. I have it in a test environment right now and it works.

Edit: I copied the color proc wrong and it would prevent compiling, fixed. The errors were very minimal, if you have issues troubleshooting those errors I suspect you are just copy paste dumping stuff others give you which is not a good way to learn.

If you have any questions please ask - I'm sure my method could even be improved upon.


Tip for you Jordan35. Instead of using /obj/ for overlays use images. They're purely visual but carry layers, names, and anything else you might need for overlay systems. Plus images can have their own overlays as well.
In response to Jittai
yeah your code works,just one question,every hairstyle i have has many states,so if i put them all in one hair.dmi how will i let the code know which one to get?
And no i dont copy paste,i just get the code use it once to see how it orks,and then try to to create something that works the same with what i know
You mean states like jumping, punching or such? If so, then you're going to have to rework how the images are created and avoid using the icon_states() trick.

Worst case scenario you may have to have each hair in its own icon.

usr.hair = image('Hair.dmi',hair_state,layer=MOB_LAYER+0.01) ->
usr.hair = image(file("[hair_state].dmi"),layer=MOB_LAYER+0.01)


hair = image('Hair.dmi',hair.name,layer=MOB_LAYER+0.01) ->
hair = image(file("[hair.name].dmi"),layer=MOB_LAYER+0.01


Changing those two lines allows for multiple states per hair, like dead or punching or whatever. But you need to have one hair per icon.
In response to Jittai
Yeah these kind of states,i am thinking on adding a number in the front of states names,so i can use (if) and set which type of hair get which states,could that work?
I told you how to make it work. In each icon you just need the same state names as the poses for mobs.

Mob icon has states: default, running, dead
Hair icons have: default, running, dead
In response to Jittai
ah got it,thank you very much for your help
Any time.
In response to Jittai
Jittai wrote:
 mob/barber
//icon = 'Barber.dmi'
//icon_state="Barber"

DblClick()
..()

if(get_dist(src,usr)>1) return//more efficient than range()/view()
//Avoid heavy/unnecessary indenting to help readability

if(alert(usr,"Hello [usr], want your hair changed?","[src]","Yes","No")=="Yes")

var/hair_state = input(usr,"What style would you like?","[src]") as anything in Hairs+list("Bald")
if(!hair_state) return

usr.overlays -= usr.hair
if(hair_state!="Bald")//make sure to include a blank "bald" state in the dmi
usr.hair = image('Hair.dmi',hair_state,layer=MOB_LAYER+0.01)
usr.hair.name = hair_state
//this stores the icon_state in a niffty way for later use

//Hair.dmi should be an icon where all your hair states are in
//hair_state = the hair's icon_state
//layer should be what ever your mob is +0.01 so the hair is really close to it's layering

var/hair_color = input(usr,"What color would you like?","[src]",usr.hair.color) as color
if(hair_color) usr.hair.color = hair_color

usr.overlays += usr.hair

mob/proc/ColorHair(color)//just color not style change
if(!hair) return
hair.color = color

mob/var/image/hair = null
var/list/Hairs = list("Afro")



if you move the check a little higher you can remove a little redundancy and the need for a bald.dmi.
You have to set the hair as the "bald" icon or null though in case another code interacts with the hair. Also the hair coloring was a optional thing to show how dyeing the hair by itself would work.