putting image in label

Ral
Posts: 7
Joined: Sun Apr 25, 2010 6:48 pm

putting image in label

Post 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

User avatar
Vadi
Posts: 4854
Joined: Sat Mar 14, 2009 3:13 pm

Re: putting image in label

Post by Vadi »

setBackgroundImage("X", "C:\images\mudimages\1.png" ) ?

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: putting image in label

Post by Heiko »

Instead of gfx_path = "/home/heiko/gfx"; put gfx_path = [[C:\images\mudimages]]

Ral
Posts: 7
Joined: Sun Apr 25, 2010 6:48 pm

Re: putting image in label

Post 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

WillFa
Posts: 19
Joined: Mon May 10, 2010 4:16 pm

Re: putting image in label

Post 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/"

Naito
Posts: 18
Joined: Thu Aug 12, 2010 1:36 pm

Re: putting image in label

Post 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

User avatar
Omit
Posts: 190
Joined: Sun Aug 01, 2010 10:54 pm
Location: Middle Earth
Contact:

Re: putting image in label

Post 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.)

Naito
Posts: 18
Joined: Thu Aug 12, 2010 1:36 pm

Re: putting image in label

Post 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....

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: putting image in label

Post 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.

Naito
Posts: 18
Joined: Thu Aug 12, 2010 1:36 pm

Re: putting image in label

Post 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.

Post Reply