ID:2078706
 
(See the best response by Lummox JR.)
Code:
var/const
HAIR_LAYER = FLOAT_LAYER-3
var
Mullet
Gotenks
obj/overlay
hair
icon = 'hairstyles.dmi'
icon_state = "Mullet"
pixel_y=1;layer=100;pixel_x=0
layer = HAIR_LAYER
hair1
icon = 'hair.dmi'
icon_state = "Gotenks"
pixel_y=1;layer=100;pixel_x=0
layer = HAIR_LAYER
mob/player/verb
style_hair()
input("Please select a hair style.") in list("Mullet","Gotenks")
if("Mullet")
overlays += /obj/overlay/hair
else if("Gotenks")
overlays += /obj/overlay/hair1


Problem description:Above is code for a hair verb, I found part of it on this forum and tried to modify it to fit my needs. What I want is once you have used the verb, an input with a list of options(currently 2 options) to pop up and have you select what hairstyle you want. What's happening is either option you pick you still end up with the Mullet. I know this code isn't right but it's compiling fine. Still new to this so any help is appreciated.

-BIGBROYO

It's precisely because your style_hair() proc does not store the received input in a variable; the action of choice is carried out but not stored for later evaluation.
So is there a work around for this? I want a verb that allows you to pick the style of hair you want. Does everything with DM have to be complicated haha.
In response to BIGBROYO
DM only seems complicated because you are lacking in the fundamentals area. It's actually simpler compared to most other languages you would use nowadays. You are doing yourself a disservice assuming otherwise.

I explained your problem exactly in my previous post. To expand a bit and give you something to look at, let's say I wanted to make a verb that adds two numbers together:

// assume that src is a client mob
var/a = input(src, "Enter a number: ", "Addition") as null|num
if(isnull(a)) return

var/b = input(src, "Enter a number to add to [a]", "Addition") as null|num
if(isnull(b)) return

var/c = a + b


Notice how I stored the numbers given via the input() proc into the variables a and b respectively. Because of this, I was able to add my two numbers together and store the result into the c variable.
In response to BIGBROYO
BIGBROYO wrote:
So is there a work around for this? I want a verb that allows you to pick the style of hair you want. Does everything with DM have to be complicated haha.

It's pretty simple. You're not storing the result in a variable or calling it in a switch statement.

var/choice = input("Yes or no?") in list("Yes","No")
if(choice == "Yes")
do stuff
else if(choice == "No")
do something else

// this would get extremely tedious with if/else spam
// you could use switch in those cases

var/choice = input("Choose.") in list("Lige","Ter13","You")
switch(choice)
if("Lige")
// yay for me
if("Ter13")
// yay for Ter13
if("You")
// yay for you

// You could also skip attaching input in a var, for whatever reason.
// Like so.

switch(input("narto? dbz? bleech?") in list ("narto","dbz","bleech"))
if("narto")
// hokage
if("dbz")
// ssgss
if("bleech")
// iq++
Just to chime in here, you can simplify your code a lot by not using separate type paths for each hair overlay. (Also, if you can avoid a pixel offset that's even better.) For instance, you could have a global list of available hairstyles:

var/list/hairstyles = list("mullet", "afro", "stupidbowlcut", "mohawk")

After the hair choice, you could do something like this:

var/obj/hair/H = new
H.icon_state = hairstyle
// additive color
H.color = list(null,null,null,null,haircolor)
overlays += H

Or if each hairstyle has its own icon (which might make sense if you want it to track with the icon state of the parent mob), you could go this way:

var/list/hairstyles = list(\
"mullet" = 'hair_mullet.dmi',
"afro" = 'hair_afro.dmi',
...
)

And then for the hair choice:

var/obj/hair/H = new
H.icon = hairstyles[hairstyle]
// additive color
H.color = list(null,null,null,null,haircolor)
overlays += H
I understand what you guys are saying about making a var list, but when do you implement that in the verb? Or do you even make a verb? None of you put a verb in your post... Is it possible to have a verb that gives you multiple options for a hair style? Right now that's what I am looking for. An example to an answer would be, the var goes here under or above said verb. I appreciate the way you guys try to help teach people while you post, but the verb itself was my real question. Knowing the stuff you guys posted above will help me but it won't get me all the way there.

-BIGBROYO
In response to BIGBROYO
In your style_hair() verb:

// this line and below is where you'd be making your changes
input("Please select a hair style.") in list("Mullet","Gotenks")
Personally, I wouldn't do this as a verb. Picking a hairstyle is something to do at character creation time, or in some kind of character modification area, either of which is something you should be doing with an easy-to-use interface instead of a verb. I wouldn't actually use input() for this for the same reason, but I wrote the code that way for example purposes.
In response to Lummox JR
Lummox JR wrote:
Personally, I wouldn't do this as a verb. Picking a hairstyle is something to do at character creation time, or in some kind of character modification area, either of which is something you should be doing with an easy-to-use interface instead of a verb. I wouldn't actually use input() for this for the same reason, but I wrote the code that way for example purposes.



Thanks for the replies. I know a lot of games use a character creation or a barber set up. I wanted to make it to where you could change your hairstyle anywhere you want. I am still a bit confused about what to put under the if statements. I know this is wrong but here was my best guess.

mob/player/verb
style_hair()
var/list/hairstyles = list( "Mullet" = 'Mullet.dmi', "Gotenks" = 'Gotenks.dmi')
switch(input("Mullet? Gotenks?") in list("Mullet","Gotenks"))
if("Mullet")
overlays += /list/hairstyles/"Mullet"
if("Gotenks")
overlays += /list/hairstyles/"Gotenks"


Any help will be appreciated.

-BIGBROYO
The hairstyles var is an associative list. Therefore, the thing you want to add--which is what I put in my code--would be hairstyles[choice] which is an icon file (where choice is the result of the input), or else a temporary obj that was given that icon like I showed in my code.

You seem to be struggling a lot with the basics of the language at this point. I would strongly advise giving the DM Guide at read through if you haven't already, because it can give you a lot of the foundation you need to work from code examples.
switch(input("Mullet? Gotenks?") in list("Mullet","Gotenks"))

Should be
var/hair = input("Hairstyle","Hairstyle") in hairstyles

Delete everything below this line and do
overlays += hairstyles[hair]

But you really need to look at the guide, because it is obvious that you have no idea how something as basic as the syntax of the language works. Stop trying to do things when you don't even understand the basics..
Also, with input() on a list you should always include "as null|anything", because that gives the user a cancel option. If the result of input() is null, either they canceled or they logged out.
In response to Lummox JR
Oops! forgot to include that. Here's the revised version:
var/hair = input("Hairstyle","Hairstyle") as null | anything in hairstyles
overlays += hairstyles[hair]

Thanks, Lummox.
In response to GreatPirateEra
You forgot to check if hair is null, though.
I have already read the DM guide, more than once. Thanks for the criticism, but I would recommend in the future that you do not push people away from learning by bluntly saying that they are not getting it, go somewhere else and learn it. I assume these forums are here to help people learn as well as provide a community to Byond coders/gamers. When you push people away like that it makes people want to quit where they're at and just leave Byond. I can tell from reading the forum posts that some people would prefer that community stay small, if that's the case I am sorry for inconveniencing you by asking for help. I learn best by seeing real examples with comments that explain what the code is doing.

I tried your example and now the hair doesn't even appear.

mob/player/verb
style_hair()
var/list/hairstyles = list( "Mullet" = 'Mullet.dmi', "Gotenks" = 'Gotenks.dmi')
var/hair = input("Mullet","Gotenks") as null | anything in hairstyles
overlays += hairstyles[hair]



I am literally taking exactly what you say to heart. All of it. I will give the DM guide another read and try to figure out these "syntax" and "fundamentals" that I appear to be missing out on. In the mean time if you have any code related comments you can share that pertain to my problem please share them.

I mean some of these //

thanks

-BIGBROYO
In response to Lummox JR
I don't see the need for it? if they log out, then the input won't go through anyways, and if they cancel, it shouldn't even attempt to proceed on changing their hair. Am I missing something? checking for null seems unnecessary.
Make sure that your icons Mullet.dmi and Gotenks.dmi have the necessary icon_states. Currently you are only using the icons with no set icon_state, so it's looking for a blank ("") state. If there isn't one, you will not see anything.

Also, GreatPirateEra is not trying to push you away or belittle you. We only want to help you, but that is difficult when you don't understand even the most basics of the language. You say you have read the DM guide more than once, but from our perspective that remains to be seen.

Reading is no good if you do not understand what it is you read.
Where does the icon_state go?

-BIGBROYO
In response to BIGBROYO
You really should read the DM guide. As it stands, you're shooting blankly in the dark and only hitting the mark with a lot of help.
Page: 1 2