Page 1 of 1

[SOLVED] Is it possible to use variables in Ren'Py statements?

Posted: Mon Jun 24, 2019 6:51 pm
by vorgbardo
This is probably a very daft question, but I couldn't find an answer anywhere. Is it possible to use a variable as part of Ren'Py statements, and if yes, how? For example, say that I have five status images (status1.png ... status5.png), and at times during the game I wish to show one that matches the current "status" variable value (1-5). Is there a way to do something like this (the example is obviously non-functioning):

show status+$status.png

Hopefully I managed to explain this so that it makes sense, please ask if any clarification is needed.

Re: Is it possible to use variables in Ren'Py statements?

Posted: Mon Jun 24, 2019 8:45 pm
by philat
show expression. https://www.renpy.org/doc/html/displayi ... -statement (you have to scroll down a bit to find show expression)

show expression "status"+status+".png"

Re: Is it possible to use variables in Ren'Py statements?

Posted: Tue Jun 25, 2019 6:15 am
by Remix
You could alternatively define an image that interpolated the variable part in the name string:

Code: Select all

default current_status = 1
image status = "images/status[current_status].png"

label start:
    show status
    "..."
    $ current_status = 2 # now showing status2.png automatically

Re: Is it possible to use variables in Ren'Py statements? [SOLVED]

Posted: Tue Jun 25, 2019 8:38 am
by vorgbardo
Thank you kindly for the answers, worked perfectly!

Just in case someone has the exact same problem I had, as my status was an integer, I had to make it a string first to get it work with the first solution:

show expression "status"+str(status)+".png"