ID:162612
 
When using winset, what is the syntax for passing in an image parameter through a variable, rather than explicitly typing out the file's name?

I'm under the impression it can't be done.. do files have to be defined in the compiler before the code will compile? Does this actually mean I'm going to have to write a program to manually type out winset statements for the 100+ images and button states that I have?
No one?
You aren't being clear enough. What exactly are you trying to do? You want to attach a file to a variable?
In response to DivineO'peanut
Yes.

So you can do something like

winset(Person, "window", "image = [var]");

where var is a filename.


to avoid having to do

switch(state){


if(1) winset(Person,"window", "image = 'file1.png");
if(2) winset(Person,"window", "image = 'file2.png");

...

if(1000) winset(Person, "window", "image = 'file1000.png");

}
In response to Obs
Oh, damn, I thought you wanted to set it to an actual /image or /icon object, and spent half an hour trying to figure out how to do that. To do what you want, you just need to put double quotes around the variable. Escaped, obviously.

winset(Person, "window", "image=\"[var]\"")


It will have to do a run-time search for that file, however. I can't recall exactly how caching works off the top of my head, but it should be okay.
In response to Garthor
That does not work.
In response to Obs
Weird. After fiddling around a bit more, the quotes aren't needed at all. This is exactly what I did to get this to work:

    var/i = "mob.dmi"
winset(src,"default","image=[i]")


What, exactly, are you trying that doesn't work?
In response to Garthor
1) I'm using pngs, not DMIs.


2) A small slice of the code, with some test cases:

This works as it should for the case:
    var/test = "vchest_selected_5.png";
var/test2 = "TargetChest";

if(Subject.TargetZone != Target){
//Selecting new target
DEBUGMSG("In TargetZone");
if(Subject.TargetZone){
winset(Subject, "[test2]", "image=['vchest_selected_5.png']");



This goes straight to hell:
    var/test = "vchest_selected_5.png";
var/test2 = "TargetChest";

if(Subject.TargetZone != Target){
//Selecting new target
DEBUGMSG("In TargetZone");
if(Subject.TargetZone){
winset(Subject, "[test2]", "image=[test]");



What you are doing, should not be possible.

And I've tried changing the format to DMI. Same problem/
In response to Obs
What type of element is TargetChest?
In response to Garthor
A button.
In response to Obs
Ah, okay, I figured out the problem. It was rather obtuse:

Using winset() will not retrieve the file if it's not in the cache.

So, simple solution: call fcopy_rsc(test) before you use winset(), which will forcibly load the file into the resource file. This will generate a warning, because the compiler insists this has no effect. You can safely do test=fcopy_rsc(test) to just get rid of that warning, however.

I'm not quite sure what the exact effect of this on clients will be. An alternative solution would be to force the files to be included in the .rsc at compile-time, by including a reference to them in single-quotes anywhere else. This can be done instead of using fcopy_rsc().
In response to Garthor
Ah so that's how you cache files....and I was also wondering the same thing.

EDIT: It seems it doesn't work. I am also using a .png.
In response to Garthor
I'll try it in a bit, but the dude below said he tried it and failed.
In response to Garthor
Garthor wrote:
Ah, okay, I figured out the problem. It was rather obtuse:

Using winset() will not retrieve the file if it's not in the cache.

So, simple solution: call fcopy_rsc(test) before you use winset(), which will forcibly load the file into the resource file. This will generate a warning, because the compiler insists this has no effect. You can safely do test=fcopy_rsc(test) to just get rid of that warning, however.

I'm not quite sure what the exact effect of this on clients will be. An alternative solution would be to force the files to be included in the .rsc at compile-time, by including a reference to them in single-quotes anywhere else. This can be done instead of using fcopy_rsc().


Ok, so this worked.

Now I want to analyze exactly what fcopy is doing here.

Does this have a chance of creating more copies than it should? If the same fcopy code is called multiple times is it making multiple copies in the cache?
In response to Obs
I have not actually used fcopy_rsc() before, so I'm not entirely sure what the side effects of using it may be. I'm also not sure what will happen when you put this online (whether or not the file will be fetched from the server properly). Someone else may have a better idea.

In retrospect, just including a list somewhere with all the files you want added to the cache would be ideal. Just something like

var/list/resources = list('file1.png','file2.png')


You don't need to use it, but just the presence of a single-quoted file should load it into the resource file at compile-time.
In response to Garthor
Garthor wrote:
I have not actually used fcopy_rsc() before, so I'm not entirely sure what the side effects of using it may be. I'm also not sure what will happen when you put this online (whether or not the file will be fetched from the server properly). Someone else may have a better idea.

In retrospect, just including a list somewhere with all the files you want added to the cache would be ideal. Just something like

var/list/resources = list('file1.png','file2.png')

You don't need to use it, but just the presence of a single-quoted file should load it into the resource file at compile-time.

I guess I could do that.

But the idea was to avoid having to write out 100+ file names.
In response to Obs
You can write a small program whose only purpose would be to go through all the files in a folder and fcopy_rsc() them all. Then, you can take the generated .rsc and #include it in your main project. But you'd have to re-run that every time you make a change, so that's not ideal.

You could fcopy_rsc() all the files in world/New(), just once. That should work well enough.
In response to Garthor
I could do that too.

But I've already implemented the array.

Put it all under World New().
Obs wrote:
I'm under the impression it can't be done..

Bingo. It can't be done, at least not through the code.
But so long as the skin is setup to use those images from the start, you don't need to code it in at all.

-- Data
In response to Android Data
Way to ignore the entire thread where we did, in fact, make it work.
Page: 1 2