Variables in image paths?

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

@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.

1 Like

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);

1 Like

I find an indirect way to do it with gosub_scene. just create a new scen called images. then use gosub_scene variable and go to a label that just contain the *image path and return.

2 Likes

Seven years later. But still a golden hack!

Thanks for sharing it @Dralctig!

I commented to this in another thread. It looks like you can just do this now:

*image base_${var}.jpg

2 Likes

By the way, *sound unfortunately doesn’t have the same flexibility. It doesn’t replace variables.

I’ve found success with

*image @{variable+1 |first|second|third}.png
1 Like