ID:139926
 
Problem description:
So Im trying to have the background image file change based on what nation they are in. right now Im using a if this nation then image=this file system and it works but I have to change a bunch of windows colors so I created an associate list and I got it to work for everything except the background image for the main window. Heres the code

Code:
//this is for the windows no real problem with this and the list
var/list/setup=list("Earth Kingdomb"="#7C581B","Earth Kingdom"="#2F4A13","Fire Nationb"="#D68B10","Fire Nation"="#4D1F13","Air Nomadb"="#BE541B","Air Nomad"="#E6B042","Water Tribeb"="#E9F3F5","Water Tribe"="#52628D")
winset(src,null,"chatoutput.background-color=[setup[src.Nation]];chatinput.background-color=[setup[src.Nation]];output1.background-color=[setup[src.Nation]]")
//using this currently for each nation but trying to figure out how to put a variable in the file lookup
if(src.Nation=="Earth Kingdom")
winset(src,"MainWindow","image=['backgroundearth.png']")

Im trying to do some can of entry for the file name in the list and have it load it that way so something like this
winset(src,"MainWindow","image=['[setup[[src.Nation]background]]']")
As of this moment, you can't use variable names in order to point to resource files. You're definitely not going to be able to do so in the manner you're trying, because Dream Maker needs to know what resource file to include at compile-time, so it cannot be non-constant.

You'd have to handle it differently, for example by matching the identifier to the resource file reference.
proc/get_background(color)
switch(color)
if("red") return 'red.dmi'
if("blue") return 'blue.dmi'

//the same is possible with an associative list.

var/list/colors = list("red" = 'red.dmi',"blue" = 'blue.dmi')
In response to Kaioken
if im understanding you correctly, I tried that and still didnt get it. I have the resource file defined in the list like so
var/list/setup=list("Water Tribeback"="backgroundwater.png")

so then when i did the code for the winset it should place 'backgroundwater.png' in the file location

//src's nation is defined like this
mob/player/var/Nation="Water Tribe" //or to that effect

//so with this in a proc
winset(src,"MainWindow","image=['[setup["[src.Nation]back"]]'")
//should be the same as
winset(src,"MainWindow","image=['backgroundwater.png']")


Or at least thats how im reading it
In response to NightJumper88
Look at my example code again.

NightJumper88 wrote:
"image=['[setup["[src.Nation]back"]]'")


Again, you can't use vars in any way (such as in embedded expressions) in the names of resource files. When you use single quotes (') around a filename, you're not making a text string. You're designating a resource file. That doesn't work like a text string does. So the above doesn't work for the same reason this won't:
var/n = rand(1,2)
var/X = 'file[n].dmi'


What the above does is simply tell Dream Maker to look for a file with the name "file[n].dmi" in the project's folder. Of course, there isn't one.
So you need to put that first ' outside the embedded expression as well, or have no ' characters there at all. Then it should work.
At any case, you don't really have to use a cache file reference (something in single quotes) here. When you embed a cache file reference in text, you just get a text string with the filename, anyway. To display an image in an interface control, you can simply refer to the file by giving its filename in a text string (text string means double quotes). Note that for the file to be available to players, it needs to be included in the RSC, and in order to do that you do need to use it in single quotes somewhere in your code. So if you never mention that filename in single quotes before, you may find you need to "needlessly" mention it in your code just so it gets included, like this:
proc/Dummy_proc()
return
return list('graphics/myfile.png')

//or you may opt to do it in the same proc doing the displaying

var/include = 'graphics/myfile.png'
winset(player,"label1","image=myfile.png")

Of course, in your case it's already included as you refereed to the file in a list.
In response to Kaioken
Ok so basically there is no real way to try and condense the way I was doing it with checking like this:
if(src.Nation=="Earth Kingdom")
winset(src,"MainWindow","image=['backgroundearth.png']")
if(src.Nation=="Fire Nation")
winset(src,"MainWindow","image=['backgroundfire.png']")
if(src.Nation=="Air Nomad")
winset(src,"MainWindow","image=['backgroundair.png']")
if(src.Nation=="Water Tribe")
winset(src,"MainWindow","image=['backgroundwater.png']")

Was just trying to figure out how to make one code that could handle it for each nation. Oh well already have it written like this so guess ill leave it
In response to NightJumper88
Once more, if you set up the cache file references in an associative list and use that then it will be foolproof.
var/list/colors = list("red" = 'red.dmi',"blue" = 'blue.dmi')

var/clr = pick("red","blue")

var/img = colors[clr]

winset(player,"label1",{"image="[img]""})

That or instead of the list, you could farm out the if()s into an external switch(), as also shown previously.
In response to Kaioken
ok thank you now I got it working, at least it works from what I got from your post this is what I did and it work
var/list/setup=list("Water Tribeback"='backgroundwater.png')
winset(src,"MainWindow","image=[setup["[usr.Nation]back"]]")


Ok so it worked and changed it which is good, now will having the file like that in the list include it in the compile?

And thanks for the help
In response to NightJumper88
NightJumper88 wrote:
now will having the file like that in the list include it in the compile?

As long as you simply mention a file in single quotes and that code successfully compiles, then the file is included in the RSC archive. It doesn't matter how and when you mention the file as long as the compiler doesn't output an error about it.
So, yes.

And thanks for the help

You're welcome.