Variables in image paths?


#1

It’s a long shot, I’ve tried most ways I can think of and the command doesn’t seem to support it.
I thought I’d try here just in case.

What I’m trying to do is use an image on a page depending on a variable (without using loads of *ifs)

E.g.

`

*image {pic_id}.png
`
Where pic id would be a number between 1 and 10 previously set, but currently it just tries to find the literal image “{pic_id}.png”

Can anyone comment on this? Have you managed to do it or do you know if it is actually impossible with the current version of c/s ?

Thanks in advance


#2

@CJW, I think you’re out of luck unless you hack the CS interpreter. Looking at the CS interpreter code, I don’t see any parsing of the image source being done; it is taken literally, as you experienced.

It also looks like it might not work right if the image file name has any spaces in it. Just another observation.


#3

I managed to make a separate command, just a modified version of the original *image but it’s passing a stats. variable from mygame.js as the source with +".png" - I can change the value of the variable via choicescript when required, so that’s done the trick nicely :slight_smile:

You could probably also use a variable for the .png part, in case you wanted additional extensions.

Incase anyone is interested:

printImage((stats.my_image+ ".png"), alignment);