Among the many things you could do, three simple ones would be:
- Using a <<switch>> macro with line continuations.
- Pulling the image path randomly from an array using the <Array>.random() method.
- If your image names are regular (i.e. image1.png, image2.png, ... image29.png), constructing the image path programmatically.
Example 1: <<switch>> macro and line continuations
<<set $riddle to random(1, 29)>>
.
.
.
<<switch $riddle>>
<<case 1>>[img[image1]]\
<<case 2>>[img[image2]]\
.
.
.
<<case 29>>[img[image29]]\
<</switch>>
If you're only setting $riddle to select the image and do not need it afterwards, then I'd suggest either using a temporary variable or simply doing away with it altogether.
Using a temporary variable:
<<set _riddle to random(1, 29)>>
.
.
.
<<switch _riddle>>
Doing away with it entirely:
<<switch random(1, 29)>>
Example 2: Image array example
/* You should probably do this within the StoryInit special passage. */
<<set setup.Images to [
"path/to/foo.jpg",
"path/to/bar.png",
"path/to/baz.webp",
"path/to/qaz.gif"
]>>
/* To pull an image path random from the array. */
[img[setup.Images.random()]]
Example 3: Programmatically constructing the image path
<<set $riddle to random(1, 29)>>
.
.
.
[img["path/to/image" + $riddle + ".jpg"]]
And again, if you're only setting $riddle to select the image and do not need it afterwards, then I'd suggest either using a temporary variable or simply doing away with it altogether.
Using a temporary variable:
<<set _riddle to random(1, 29)>>
.
.
.
[img["path/to/image" + _riddle + ".jpg"]]
Doing away with it entirely:
[img["path/to/image" + random(1, 29) + ".jpg"]]
PS: The eq operator is the lazy equality test operator and not the assignment operator, which is to. Also, I generally recommend the use of the strict equality test operator, which happens to be is. See <<set>> and <<if>> for more information.
/* WRONG */
<<set $riddle eq random(1, 29)>>
/* CORRECT */
<<set $riddle to random(1, 29)>>