Page 1 of 2

putting image in label

Posted: Sun May 23, 2010 11:18 pm
by Ral
Hello. I really enjoy mudlet and it has countless possibilities for things to enhance one's gameplay experience. My only problem is, i don't seem to be able to put an image into a label/button. I looked at the manual and found this:
-- define the path to the location of the images
-- this needs to be adapted to your own system e.g. "c:\images\mudimages"
-- on my linux system the folder are in my home directory in the folder gfx
gfx_path = "/home/heiko/gfx";

-- determine the size of your screen
WindowWidth=0;
WindowHeight=0;
WindowWidth, WindowHeight = getMainWindowSize();

-- create clickable compass with clickable images = labels with on click callback functions
createLabel("north",82,WindowHeight-220,50,50,1);
setBackgroundImage("north",gfx_path .. "/n.png" );
setBackgroundColor("north", 0,0,0,0);
setLabelClickCallback("north", "walk_north" )
i adapted the gfx_path to my systems', which is like the example, C:\images\mudimages. But it won't put any image in my label/button. I tried to get rid of the whole gfx_path thing, by deleting it and putting something like "setBackgroundImage("X", C:\images\mudimages\1.png" ); but it also won't work.

SO, can anyone help me with this? Thanks in advance

Re: putting image in label

Posted: Mon May 24, 2010 12:03 am
by Vadi
setBackgroundImage("X", "C:\images\mudimages\1.png" ) ?

Re: putting image in label

Posted: Mon May 24, 2010 9:27 am
by Heiko
Instead of gfx_path = "/home/heiko/gfx"; put gfx_path = [[C:\images\mudimages]]

Re: putting image in label

Posted: Mon May 24, 2010 11:28 am
by Ral
hrm, i previously used setBackgroundImage("furylabel", gfx_path .. "\1.png" ); instead of "/", to match the "\" from the C:\images\mudimages. Then i decided to use "/" as in the manual, that is:

Code: Select all

gfx_path = [[C:\images\mudimages]]

createLabel("furylabel",568, 890, 64, 64, 200);
setBackgroundImage("furylabel", gfx_path .. "/1.png" );
setBackgroundColor("furylabel", 0, 0, 0, 0);
setLabelClickCallback("furylabel", "smitefury");
plus changed the gfx path to like Heiko said and made sure that the filename is within quotation marks and it worked like a charm

thanks guys :D

Re: putting image in label

Posted: Mon May 24, 2010 6:42 pm
by WillFa
In regular strings, Lua uses \ as an escape character. Like when concatenating "\n" in for a new line, it's reading the "\i" as a metacharacter.

To fix it, you can either:
1. double up the backslashes in a regular string. "C:\\images"
2. Use Lua's long strings like Heiko suggested. [[C:\images]]
3. Lua's file libraries typically handle the / or \ conversion for you. Even on windows you can use unix style / path separators. "C:/images/"

Re: putting image in label

Posted: Mon Aug 23, 2010 9:20 pm
by Naito
Code: [show] | [select all] lua
  createLabel("Aeon",960,33,280,30,1);
  setBackgroundImage("Aeon",gfx_path .. "/Button.png");
  echo("Aeon", "<strong style=\"font-size: 125%;\"><center>Aeon</center></strong></p>")
I have that for my coding to try and put in an image into my Label of 'Aeon' and I have:
Code: [show] | [select all] lua
gfx_path = [[/home/thomasprice]]
So I can do it as above... But it's not working... Anyone know why? I'm using Ubuntu

Re: putting image in label

Posted: Mon Aug 23, 2010 9:52 pm
by Omit
http://forums.mudlet.org/viewtopic.php?f=8&t=1632

Try that... It will ask you where it is and then store the location of the folder and should work on any platform.
(Just copy and paste the code to the head of the script... then just use the gfx_path variable any time you need the path.)

Re: putting image in label

Posted: Mon Aug 23, 2010 10:43 pm
by Naito
That script worked... But it's still posting no picture where I want it. It's not even coming up with a warning O.o Or an .

I'm not to sure what I could be doing wrong here....

Re: putting image in label

Posted: Mon Aug 23, 2010 11:06 pm
by Heiko
The label must be big enough. Checkout this: http://forums.mudlet.org/viewtopic.php?f=6&t=95

the createXXX() functions should use all zeros as arguments as createLabel/Miniconsole() are one time only functions. If you call them a second time they will be ignored. The size + position of the label or console should be specified by proper resizeWindow() + moveWindow() instead.

Re: putting image in label

Posted: Mon Aug 23, 2010 11:14 pm
by Naito
Heiko wrote:The label must be big enough. Checkout this: http://forums.mudlet.org/viewtopic.php?f=6&t=95

the createXXX() functions should use all zeros as arguments as createLabel/Miniconsole() are one time only functions. If you call them a second time they will be ignored. The size + position of the label or console should be specified by proper resizeWindow() + moveWindow() instead.
If I'm understanding this correctly, then my coding should go from:
Code: [show] | [select all] lua
createLabel("Aeon",960,33,280,30,1);
  setBackgroundColor("Aeon",32,124,215,255)
  echo("Aeon", "<strong style=\"font-size: 125%;\"><center>Aeon</center></strong></p>")
To:
Code: [show] | [select all] lua
createLabel("Aeon",960,33,280,30,1);
  moveWindow("Aeon",960,33,280,30,1)
  setBackgroundColor("Aeon",32,124,215,255)
  echo("Aeon", "<strong style=\"font-size: 125%;\"><center>Aeon</center></strong></p>")
That meaning if I want to keep it in the position it started in of course, changing around the numbers when needed.