This is a basic example of how to do it. It will randomly display one of the 3 gifs.
HTML:
<<set $pics = ["p0", "p1", "p2"]>>
<<set _rand = random(2)>>
<<set _pic = "media/"+$pics[_rand]+".gif">>
<img @src=_pic>
It would probably be better/simpler to do it like this:
HTML:
<img @src="'media/' + either('p0', 'p1', 'p2') + '.gif'">
The SugarCube
You must be registered to see the links
(the
@
in front of the HTML attribute) tells SugarCube to evaluate the contents of the attribute (which should have quotes around it) and then set it to that. The
You must be registered to see the links
returns one of the values within it randomly. That code also avoids creating an array you don't need.
If, after that, you're still having any problems with displaying images, you should probably check out the "
You must be registered to see the links
" section of my
You must be registered to see the links
. The page explains how to display images, even when launched from the Twine editor.
Also, if you can,
please don't use GIFs. The GIF format has a maximum of 256 colors (thus they usually damage the image quality) and they get terrible compression. It's best to use PNG or SVG for icons, JPEG for photos, and MP4/h264 videos for animation. WEBM is also an acceptable alternative, though it should be used with caution (
You must be registered to see the links
).
Hope that helps!