ID:1474493
 
(See the best response by DarkCampainger.)
Code:
 mob
proc
Use_Perk(obj/Perks/Jutsus/P)
view()<<"<center><font color=white>[usr.Name] <font color=[usr.cc]>uses:"
view()<<"<center><span class = span_label>\icon [P.icon]"
view()<<"<center><font color=white>[P.name]!"
view()<<"<center><font color=[usr.cc]>[P.desc]"

obj
Perks
Jutsus
///Fire
Goukakyuu
icon='JutsuPerks.dmi'
icon_state="Goukakyuu"
name="Katon: Goukakyuu no Jutsu!"
desc=""

Earth_Spikes
icon='JutsuPerks.dmi'
icon_state="Doton"
name="Doton: Doryuso!"
desc=""


Problem Description:

Alright, so say I was to press the 'Earth_Spikes' object in the world, it would display the "Goukakyuu" icon_state instead of the "Doton" icon_state.

How do I fix this?

I know that I haven't mentioned anything about the icon_state in the Use_Perk() proc, however I'm not so sure how to do this properly. I'm sure that having it output [P.icon_state] will just give me the name of the icon_state.

Have you made sure you set the icon_state in the JutsuPerks.dmi?
Mhm.
This is the problem:
view()<<"<center><span class = span_label>\icon [P.icon]"


You are telling it to display the icon, which doesn't know what icon_state P is currently in, so the first icon_state in the file will be shown.

The easiest way to fix this would be to temporarily nullify the name of the perk and then reset it once we're done displaying the object.

Unfortunately, we can't really display graphics to the viewport that specify an icon_state without creating an icon object (and thus a cache object), or without outputting an object.

I have also taken the liberty of making this a little faster by eliminating the excess view() calls, and I also removed your open-tags.

 mob
proc
Use_Perk(obj/Perks/Jutsus/P)
. = P.name
P.name = null
view() << "<center><font color=white>[usr.Name]</font> <font color=[usr.cc]>uses:</font>\n<span class = span_label>[P]</span>\n<font color=white>[.]!</font>\n<font color=[usr.cc]>[P.desc]</font></center>"
P.name = .

obj
Perks
Jutsus
///Fire
Goukakyuu
icon='JutsuPerks.dmi'
icon_state="Goukakyuu"
name="Katon: Goukakyuu no Jutsu!"
desc=""

Earth_Spikes
icon='JutsuPerks.dmi'
icon_state="Doton"
name="Doton: Doryuso!"
desc=""
In response to Ter13
Hm. I knew it was in that part. I'm not sure what to do from here on. I tried your code below, and it shows the text, the name etc, though as expected, not the icon (nor the icon_state).

Is it worth just doing trial and error for now?
obj
Perks
Jutsus
///Fire
Goukakyuu
icon=icon('JutsuPerks.dmi',"Goukakyuu")
name="Katon: Goukakyuu no Jutsu!"
desc=""

Earth_Spikes
icon=icon('JutsuPerks.dmi',"Doton")
name="Doton: Doryuso!"
desc=""


Then you might be stuck using something like the above, and switching back to the \icon reference in the text. Honestly, it might be better to get rid of the icon() functions entirely and make each perk their own icon.
In response to Ter13
Just tried that code, though DM doesn't like it; hence the fact I received a 'bad file' error twice.
Just tried that code, though DM doesn't like it; hence the fact I received a 'bad file' error twice.

It's not an exact solution. You are going to have make an equivalent modification.

One way to get around the constant expression and bad file issue is to do something like this:

var/list/techniqueicons = list(icon('JustsuPerks.dmi',"Goukakyuu"),icon('jutsuPerks.dmi',"Doton"))

obj
New()
. = ..()
src.icon = techniqueicons[1]


The other way, is to create a unique icon file for each technique, only containing a single icon_state, and reference them individually like normal.
In response to Ter13
...I do not understand that x3. Sorry ^^.
Separate the icon states into different files.
In response to Ter13
Ter13 wrote:
Separate the icon states into different files.

Owow. That's going to be tedious. Thank you though, Ter ^^.
I can save you some time with that:

verb
separate_icons()
var/icon/i = icon('JutsuPerks.dmi')
var/icon/j
var/icon/k
for(var/v in i.IconStates())
j = icon(i,v)
k = icon('blank.dmi')
k.Insert(j,"")
usr << ftp(k,"[v].dmi")


This verb will allow you to separate each icon_state into a new file and save it on your hard drive.

Just make sure you have an icon file named blank which has a single empty icon state with no name, or it won't work.
In response to Ter13
o.o At the moment, I'm trying that out. Thanks.

Edit: Thanks for that, Ter!
In response to Ter13
Best response
Ter13 wrote:
Unfortunately, we can't really display graphics to the viewport that specify an icon_state without creating an icon object (and thus a cache object), or without outputting an object.

A little bit ago they actually addressed this issue. Now, if you manually create the <img> tag, you can specify the state, direction, and even the frame:

view() << {"<center><span class="span_label"><img style="width:32px;height:32px" src="\ref[P.icon]" iconstate="[P.icon_state]"></span></center>"}


The reference goes into more detail:
http://www.byond.com/docs/ref/info.html#/DM/text/macros/icon
What version was this addressed in? I was unaware of this change. Also: Do you know if this is the case in browsers too?
In response to Ter13
Ter13 wrote:
What version was this addressed in? I was unaware of this change. Also: Do you know if this is the case in browsers too?

Oh wow, it looks like the iconstate attribute has been around forever: 232 Release Notes

The iconframe and icondir attributes are more recent: 441.1019 Release Notes

It also looks like it's supported in maptext even:
http://www.byond.com/forum/?post=121542&page=4#comment628503

Just tried it in a browser, and it doesn't seem to work there, unfortunately.
In response to DarkCampainger
Right, so this doesn't work?
In response to Kboy33
Kboy33 wrote:
Right, so this doesn't work?

Should work fine in an output.

It's funny that hasn't been carried forward as common knowledge, if it's that old, DC. I guess it's kinda like FLOAT_LAYER, one of those things everyone should know about, but doesn't, thus making their lives harder.
Alrighty, thanks guys. I'll try it out ASAP.
Sorry to double post, but that code works perfectly! Thank you for your help once again, guys!