Howdy, Stranger!

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

Numeric variable to string

Hello again my helpful friends!

I'm trying to show a random picture on the screen. I can make this work by using the either randomiser.

(set: $image to (either: "1", "2", "3"))
(print: ' <img src = "Images/Portraits/'+$image+"LF.png"+'"> ')

The problem is that I'm quickly getting far too many pictures to keep adding them as options with "either".
In short, I'd like to have this work with the random randomiser:

(set: $image to (random: 1, 100))
(print: ' <img src = "Images/Portraits/'+$image+"LF.png"+'"> ')

The problem with this is that it considers the random variable a number, not a string.
I've tried little hacks to get this working but no luck so far:

(set: $image to (random: 1, 100))
(set: $image2 to "$image")
(print: ' <img src = "Images/Portraits/'+$image2+"LF.png"+'"> ')


Many thanks to whomever can make this work!

Comments

  • You need to state which Story Format you are using when you ask a question, as answers can be different for each one. Based on the syntax of your examples I am going to assume that you are using Harlowe.

    You can use the (text: ) macro to convert a number into a string.
    (set: $image to (text: (random: 1, 100)))
    
  • Worked like an absolute charm! (It was indeed in Harlowe)

    Thank you a dozen greyelf, you're amazing!
Sign In or Register to comment.