Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How do you pick random images from a folder

Let's say I have 3 image files to show in "living room" passage: lr1.jpg, lr2.jpg, lr3.jpg

How do I make Twine2 to pickup a random one of these and show?


  • You need to state which story format you are using, as answers can be different for each one.

    Without knowing the story format I can only explain in generalities but basically you use a random function to determine the number (1, 2 or 3) part of the image file name. You then concatenate the number with the strings "lr" and ".jpg" to format the image filename and store the result in a $variable.

    eg. $variable = "lr" + 3 + ".jpg"

    You then use the $variable along with some code to show the image.
  • I am using sugarcube.

    I was unable to call the image this way:
    <img src="$variable">
  • Use the wiki image markup:
  • I guess the same approach does not work for Harlowe, does it?

    [img[$variable]] just writes everything as text in Harlowe
  • Each story format defines it's own macro syntax and list of core macros/markup/features.

    Try the following for Harlowe:
    (set: $image to "smile.jpg")
    (print: '<img src="' + $image + '">')
Sign In or Register to comment.