Using a variable as an image name
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.
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.
-
SoupyTheCat
- Newbie
- Posts: 1
- Joined: Fri Apr 29, 2022 8:34 pm
- Location: A very comfy chair
- Discord: SoupyTheCat#6604
- Contact:
Using a variable as an image name
How would I use a variable as part of an image name when using the show command? For example, setting the variable score to 20 and using that to show the image score_20. Technically I could use a bunch of else/if statements, but that would get cluttered easily.
~ Soupy
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3636
- Joined: Mon Dec 14, 2015 5:05 am
- Location: Your monitor
- Contact:
Re: Using a variable as an image name
Theres a few ways to do this.
One way you can achieve this is via ConditionSwitch.
https://www.renpy.org/doc/html/displaya ... tionSwitch
Or you can use python and screen language.
There are probably more ways, but I find either of these more than sufficient for my needs.
One way you can achieve this is via ConditionSwitch.
https://www.renpy.org/doc/html/displaya ... tionSwitch
Code: Select all
image score = ConditionSwitch(
"score == 0", "score_00.png",
"score == 1", "score_01.png",
"score == 2", "score_02.png")
##etcetera
label start:
show score
$score += 1
"You have [score] point"
$score += 1
"You have [score] points"
return
Code: Select all
default score = 0
screen score_screen():
imagebuton:
idle "images/score_{}%s.png" .format(score)
action NullAction()
label start:
show screen score_screen
$score += 1
"You have [score] point"
$score += 1
"You have [score] points"
return
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Free Android GUI - Updated occasionally
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
- Ocelot
- Eileen-Class Veteran
- Posts: 1883
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
- Contact:
Re: Using a variable as an image name
Also: DynamicImage:
Code: Select all
image score_img = DynamicImage("score_[score].png")
< < insert Rick Cook quote here > >
Who is online
Users browsing this forum: Bing [Bot], Google [Bot], minyan