Howdy, Stranger!

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

[sugarcube] Image variable

I would like to make it so if a action is repeated in my story the image will be randomly selected from a list of 5 or so images everytime. I tried saying stuff like "set $image to either (image1.jpg, image2.jpg.....)" "[image[$image]]" but that doesn't work.

Comments

  • Please use the C button in the comment field's toolbar to wrap your code examples in code markup, it makes them easier to find and read.

    You don't state which release (1.x or 2.x) of SugarCube you are using, so I am going to assume it is 1.x

    There are two syntax errors in your example:

    1. The base image markup is [img[Image]] not [image[Image]]

    2. You need to quote the names of the images you are trying to use as parameters of the either function.

    Because you want to select from the image list multiple times and to save memory in the History system I suggest you store that image list as an Array (named images in this example) in the setup variable, this should be done in your story's StoryInit special passage.
    <<set setup.images to ["image1.jpg", "image2.jpg", "image3.jpg", "image4.jpg", "image5.jpg"]>>
    

    You can now use the Array random function to obtain the name of the image to show.
    [img[setup.images.random()]]
    

    note: you can rename the images array to whatever makes sense to you.
Sign In or Register to comment.