Using "img" tags

The Pixie
While we can use the picture script command, I was wondering if I can put HTML "img" tags in text. I had a look at what the picture script command actually does, and it uses "img" tags, like this:

<img src="quest://local/flower.jpg?c=93347006">

<img src="quest://local/flower.jpg?c=93347124">

<img src="quest://local/flower.jpg?c=93347180">

<img src="quest://local/flower.jpg?c=93347183">


These were all for the same thing (looking at an item), performed twice in a play through, two separate plays through. So what is that number? It seems to increase every time. Even if you close Quest, then start it up again this number is remembered and increased, though not be the same amount each time.

It is not required offline, but it is online, and it does seem to matter what it is. So how do I get it? And what does it do?

Alex
It's a "cache buster" to prevent the browser fetching the image from cache. It's just a number based on the current time (can't remember off the top of my head, but it'll be something like the number of milliseconds since some particular date).

The Pixie
So how come I am not seeing any image? This is the HTML code being served:

<span style="font-family:Georgia, serif;color:Black;font-size:12pt;">
<img src="quest://local/flower.jpg?c=90000001"></img>
</span>


Comparing to a picture command, I now see it is quite different online, and in fact the number is not even there!

<span style="font-family:Georgia, serif;color:Black;font-size:12pt;">
<img src="http://textadventures.blob.core.windows.net/gameresources/5b8e54c5-c011-417a-9ee5-b3c34be859e7/flower.jpg"></img>
</span>


In fact there is a whole different number, 5b8e54c5-c011-417a-9ee5-b3c34be859e7. That at least stays the same. Is that unique to a game? Can I rely on it not changing when I update a game? Hmm, I would also have to do it different for on-line and off-line.

All I really want is to insert align="left" into the HTML. Is there an alternative that would be any easier?

Alex
You can't use quest:// URLs in the browser - that's specific to the desktop version. This is why you must use the GetFileURL function to get the URL to your images, as it will always return the correct URL for the current player.

Don't rely on the textadventures.blob.core.windows.net URL staying the same either. The URL may change when a game is updated, or if the specifics of the online hosting change.

If you want to create your own img tags, or do anything else with HTML/JS that will need resources from your Quest game file, always use GetFileURL: http://docs.textadventures.co.uk/quest/ ... leurl.html

The Pixie
Thanks. Got it working now.

The Pixie
For anyone else, a couple of functions that will put an image floating in the text, either left or right; just send it the filename.

  <function name="ImageLeft" parameters="filename"><![CDATA[
msg ("<img src=\"" + GetFileURL(filename) + "\" style=\"float:left; padding:5px;\" />")
]]></function>
<function name="ImageRight" parameters="filename"><![CDATA[
msg ("<img src=\"" + GetFileURL(filename) + "\" style=\"float:right; padding:5px;\" />")
]]></function>

Silver
I'm having problems with images loading when playing online and I guess it's related to the issue Alex outlines above. So I tried doing this in code view:

GetFileURL ("myimage.jpg")
SetBackgroundImage ("myimage.jpg")


And it just gives me an error for the GetFileURL so I'm obviously doing something wrong.

jaynabonne
GetFileURL returns a value, so you have to do something with it, like print it with "msg" or assign it to a variable. You could do:

url = GetFileURL ("myimage.jpg")
SetBackgroundImage (url)

(if I get what you're trying to do).

Silver
I'll give that a try (probably tomorrow). It looks like it should work though.

If I've understood Alex properly above, that would be the only reliable way of ensuring images load online. Basically I had a background image load in. Then decided to change the location it would appear and it wouldn't load (online). Which got me thinking of GetFileURL and a google led me to this thread.

jaynabonne
Yes. The base URL is different in the desktop player and the online one, so GetFileURL hides that difference and gives you something that should work in both cases.

Silver
Cool. Thanks. Erm. I hope that isn't true of audio also although I haven't ran in to that being a problem as of yet.

Silver
Actually, my hacked in audio is html5 so not the same thing I suppose.

Silver
jaynabonne wrote:GetFileURL returns a value, so you have to do something with it, like print it with "msg" or assign it to a variable. You could do:

url = GetFileURL ("myimage.jpg")
SetBackgroundImage (url)

(if I get what you're trying to do).


This doesn't work (for me) either online or offline. Should the latter part be nested in the former (I'm purely guessing here)?

jaynabonne
Using the intermediate variable should have the same effect (if it would work). I've had cases in Quest where the nesting doesn't work, so I played it safe with a variable.

To be honest, I was just looking at the sequence you had posted. Looking now at what SetBackgroundImage actually does, it turns out that it does the GetFileURL for you. So you should just be able to do:

SetBackgroundImage ("myimage.jpg")

Silver
That's what I had done originally (and have done with all other background images). I might have gotten to the bottom of this though. It seems that when I wrote a new script for it to appear elsewhere I asked for ("myimage.jpg") where as it's named Myimage.jpg. So perhaps file names are case sensitive online but not offline? Anyway, changing the file name to lower case got it working anyway. Cheers for the help.

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums