# Variables in image paths?

**URL:** <https://forum.choiceofgames.com/t/variables-in-image-paths/524>\
**Category:** ChoiceScript Help\
**Created:** [June 4, 2012, 8:12pm UTC](https://forum.choiceofgames.com/t/variables-in-image-paths/524 "2012-06-04T20:12:45Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![CJW](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/cjw/32/111787_2.png) [@CJW](https://forum.choiceofgames.com/u/CJW)\
**Post date:** [June 4, 2012, 8:12pm UTC](https://forum.choiceofgames.com/t/variables-in-image-paths/524/1 "2012-06-04T20:12:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![eposic](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/eposic/32/198508_2.png) [@eposic](https://forum.choiceofgames.com/u/eposic)\
**Post date:** [June 4, 2012, 11:11pm UTC](https://forum.choiceofgames.com/t/variables-in-image-paths/524/2 "2012-06-04T23:11:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CJW](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/cjw/32/111787_2.png) [@CJW](https://forum.choiceofgames.com/u/CJW)\
**Post date:** [June 4, 2012, 11:47pm UTC](https://forum.choiceofgames.com/t/variables-in-image-paths/524/3 "2012-06-04T23:47:47Z")

</div>

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 🙂

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

---

<div class="post-metadata">

**Author:** ![Dralctig](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/dralctig/32/105938_2.png) [@Dralctig](https://forum.choiceofgames.com/u/Dralctig)\
**Post date:** [November 21, 2019, 4:20pm UTC](https://forum.choiceofgames.com/t/variables-in-image-paths/524/4 "2019-11-21T16:20:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Nahim\_Kerman](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/nahim_kerman/32/62734_2.png) [@Nahim\_Kerman](https://forum.choiceofgames.com/u/Nahim_Kerman)\
**Post date:** [November 24, 2019, 10:34pm UTC](https://forum.choiceofgames.com/t/variables-in-image-paths/524/5 "2019-11-24T22:34:24Z")

</div>

Seven years later. But still a golden hack!

Thanks for sharing it @Dralctig!

---

<div class="post-metadata">

**Author:** ![choicehacker](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/choicehacker/32/127936_2.png) [@choicehacker](https://forum.choiceofgames.com/u/choicehacker)\
**Post date:** [June 27, 2020, 3:59pm UTC](https://forum.choiceofgames.com/t/variables-in-image-paths/524/6 "2020-06-27T15:59:36Z")

</div>

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

\*image base\_${var}.jpg

---

<div class="post-metadata">

**Author:** ![choicehacker](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/choicehacker/32/127936_2.png) [@choicehacker](https://forum.choiceofgames.com/u/choicehacker)\
**Post date:** [June 28, 2020, 3:13am UTC](https://forum.choiceofgames.com/t/variables-in-image-paths/524/7 "2020-06-28T03:13:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![will](https://sea3.discourse-cdn.com/choiceofgames/user_avatar/forum.choiceofgames.com/will/32/132033_2.png) [@will](https://forum.choiceofgames.com/u/will)\
**Post date:** [June 30, 2020, 3:50pm UTC](https://forum.choiceofgames.com/t/variables-in-image-paths/524/8 "2020-06-30T15:50:28Z")

</div>

I’ve found success with

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