Images Not Loading Using URL Path

Post Reply
Whisky
Posts: 2
Joined: Wed Nov 29, 2017 10:48 pm

Images Not Loading Using URL Path

Post by Whisky »

Hello all!

I'm learning how to use the GUI functions with Geyser, lots of fun!

I am having a bit of trouble getting images to fit my labels using URL paths with variables.

Using the below code I can successfully get an image displaying, which hopefully proves the path is correct:

Code: Select all

ue_path = getMudletHomeDir()
setBackgroundImage("GUI.Left",ue_path.."/GUI/border_left.png")
GUI.Left is a normal label hanging out over on the left of my screen.

What I am trying to do is have an icon image display underneath a gauge.
The icon needs to stretch to fit the label in case of window resizing.

Using this code with the full path, the icon appears and stretches to fit the label nicely:

Code: Select all

GUI.HungerIcon:setStyleSheet([[border-image : url("C:/Users/matt/.config/mudlet/profiles/UnEarthed 2017/GUI/thirst.png");]]);
But when trying to replace the full file path with a variable (so the GUI can be distributed to other computers), no image displays:

Code: Select all

GUI.ThirstIcon:setStyleSheet([[background-image : url(]] .. ue_path .. [[/GUI/thirst.png)]]);
I must be using the wrong syntax here, but haven't figured it out yet.
Could anyone give me some pointers please?

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

Re: Images Not Loading Using URL Path

Post by Vadi »

What if you try this:

Code: Select all

ue_path = getMudletHomeDir():gsub([[\]], [[/]])
Does that work?

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: Images Not Loading Using URL Path

Post by Jor'Mox »

Actually, the error is pretty straight forward. In the case where you have the full path, you end that path string with a ". In the case where you are using the partial path, there is no " at the end before the closing parenthesis, nor one at the beginning for that matter. You need to follow the proper syntax, which in this case is: setStyleSheet([[background-image : url("path here")]])
So you need to change your code to this:
GUI.ThirstIcon:setStyleSheet([[background-image : url("]] .. ue_path .. [[/GUI/thirst.png")]])

Whisky
Posts: 2
Joined: Wed Nov 29, 2017 10:48 pm

Re: Images Not Loading Using URL Path

Post by Whisky »

Vadi and Jor'Mox thank you so much!

You were both on the money.
Both these additions were required to display the icon, which now stretches to fit the label

Code: Select all

ue_path = getMudletHomeDir():gsub([[\]], [[/]])
GUI.ThirstIcon:setStyleSheet([[border-image : url(]] .. ue_path .. [[/GUI/thirst.png)]]);
:D

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

Re: Images Not Loading Using URL Path

Post by Vadi »

Nice! Could you update the geyser wiki with this example for others?

Post Reply