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

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
vorgbardo
Regular
Posts: 27
Joined: Sun Jan 14, 2018 8:28 am
Projects: Head Case
Contact:

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

#1 Post by vorgbardo » Mon Jun 24, 2019 6:51 pm

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.
Last edited by vorgbardo on Tue Jun 25, 2019 8:44 am, edited 2 times in total.
A dyslexic man walks into a bra.

philat
Eileen-Class Veteran
Posts: 1853
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

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

#2 Post by philat » Mon Jun 24, 2019 8:45 pm

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"

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

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

#3 Post by Remix » Tue Jun 25, 2019 6:15 am

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
Frameworks & Scriptlets:

User avatar
vorgbardo
Regular
Posts: 27
Joined: Sun Jan 14, 2018 8:28 am
Projects: Head Case
Contact:

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

#4 Post by vorgbardo » Tue Jun 25, 2019 8:38 am

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"
A dyslexic man walks into a bra.

Post Reply

Who is online

Users browsing this forum: Google [Bot], _ticlock_