ID:1568936
 
(See the best response by LordAndrew.)
Code:
var some_icon = "cartoonanimals.dmi"
var species = "wolf"

obj.icon = icon
obj.icon_state = species


Problem description:

Long story short, I tried to set an icon via a variable and it doesn't seem to work. I tried both "cartoonanimals.dmi" and "'cartoonanimals.dmi'", but nothing happened. Is there a certain workaround or way that you have to do it?
Best response
"cartoonanimals.dmi" is simply a string that says "cartoonanimals.dmi." In order to set it to an actual icon, you have to use single quotes ('cartoonanimals.dmi'). The single quotes denote that you're including a resource file, which is then added to the resource cache upon compilation.

I suppose you could do something like...

var some_icon = file("cartoonanimals.dmi")

Edit: the above method appears to work.
If you don't include the icon file with the rest of the host files (.dmb, .rsc) when distributing the game, then file() can't access it. This means you can't do things like:
var some_icon = file("[gender] [race].dmi")


Instead, you'd have to do something like:
var icons[] = list(
"male human" = 'male human.dmi',
"female human" = 'female human.dmi',
// ...
// this list can be generated with flist() and text2file()
)

// ...
var some_icon = icons["[gender] [race]"]
on the other hand, the advantage(i guess in some cases) is to have all the files local for modding to your liking.

I guess what I mean by that is that if you have all the resources called by using file() you can change the file whenever.

It will be like installing minecraft and changing some of the resource image files just to have your own "texture" persay. haha
In response to LordAndrew
LordAndrew wrote:
"cartoonanimals.dmi" is simply a string that says "cartoonanimals.dmi." In order to set it to an actual icon, you have to use single quotes ('cartoonanimals.dmi'). The single quotes denote that you're including a resource file, which is then added to the resource cache upon compilation.

I suppose you could do something like...

> var some_icon = file("cartoonanimals.dmi")
>

Edit: the above method appears to work.

That did it for me. Thanks a ton!
This note explains the exception to LordAndrew's post, and explains why it works in some instances and not others.

Many DM instructions that deal with files treat file("name") and "name" the same. There are cases such as browse() where a simple text string is not interpreted as a filename; it is in those situations where file() is really necessary.