Is it possible to use a variable when "show" ing something?

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
zankizuna
Veteran
Posts: 416
Joined: Fri May 04, 2012 2:20 am
Projects: Softwar
Deviantart: raseru09
itch: ZanKizuna
Location: Manilaaaaaaaa
Contact:

Is it possible to use a variable when "show" ing something?

#1 Post by zankizuna » Wed Apr 06, 2016 2:24 am

I would like to show an image, but I want it to vary
depending on a condition cited before the show statement.
I know I can just make labels for so many show statements,
but I want to make the program not code heavy, coz it'd kinda look ugly that way imo.

there is supposed to be like, about 100 or over 100 conditions
in short I want to make it something like this, please tell me how to do it right..

image ImageA=("ImageA.png")
image ImageB=("ImageB.png")
image ImageC=("ImageC.png")
image ImageD=("ImageD.png")
*... and so on...*

if (x==1):
$ variable=ImageA
elif (x==2):
$ variable=ImageB
elif (x==3):
$ variable=ImageC
elif (x==4):
$ variable=ImageD
*.... and so on...*
*some more codes*

show [variable] at position2
^
just a pseudocode sort of thing of what I want to happen...
I know this code won't work, please tell me how to do it correctly.
I just want to reduce the show statements...

Thanks!
Last edited by zankizuna on Wed Apr 06, 2016 2:27 am, edited 1 time in total.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Is it possible to use a variable when "show" ing somethi

#2 Post by xela » Wed Apr 06, 2016 2:27 am

Look into ConditionSwitch...
Like what we're doing? Support us at:
Image

User avatar
zankizuna
Veteran
Posts: 416
Joined: Fri May 04, 2012 2:20 am
Projects: Softwar
Deviantart: raseru09
itch: ZanKizuna
Location: Manilaaaaaaaa
Contact:

Re: Is it possible to use a variable when "show" ing somethi

#3 Post by zankizuna » Wed Apr 06, 2016 2:33 am

Ahhhh! Thanks! so....
All I have to do is make all Images go like this??

image Images= ConditionSwitch(
"Image == 'A'", "ImageA.png",
"Image == 'B'", "ImageB.png",
"Image == 'C'", "ImageC.png",
"Image == 'D'", "ImageD.png",
)

$Image=A
show Images at position2


Thanks a lot!

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Is it possible to use a variable when "show" ing somethi

#4 Post by Onishion » Wed Apr 06, 2016 5:28 am

Yup, and if you have that many images, you might want to consider layering multiple images, like faces/hair/clothing over a body to reduce redundancy, up to you though.

User avatar
zankizuna
Veteran
Posts: 416
Joined: Fri May 04, 2012 2:20 am
Projects: Softwar
Deviantart: raseru09
itch: ZanKizuna
Location: Manilaaaaaaaa
Contact:

Re: Is it possible to use a variable when "show" ing somethi

#5 Post by zankizuna » Wed Apr 06, 2016 9:59 am

ah... as of that... I need plenty of unique objects for my 'VN'...
actually It's more of a game hahaha :P

User avatar
korova
Veteran
Posts: 217
Joined: Sat Jun 27, 2009 5:15 pm
Completed: Ivy, Chocolate, Time, Clair Obscur
Projects: Writing exercises, The House [Nano18]
Tumblr: korova08
itch: korova
Location: Normandie, France
Contact:

Re: Is it possible to use a variable when "show" ing somethi

#6 Post by korova » Wed Apr 06, 2016 10:13 am

I think from the latest version of Renpy, you can also try something like that

Code: Select all

default letter = "A"
image Images = "image[letter].png"
and then during your game you just change the variable "letter", and the image Images will change accordingly.
(I use something like that in the last VN I'm -still- working on)

source : https://www.renpy.org/doc/html/changelo ... mic-images

User avatar
zankizuna
Veteran
Posts: 416
Joined: Fri May 04, 2012 2:20 am
Projects: Softwar
Deviantart: raseru09
itch: ZanKizuna
Location: Manilaaaaaaaa
Contact:

Re: Is it possible to use a variable when "show" ing somethi

#7 Post by zankizuna » Thu Apr 07, 2016 1:57 pm

wow, thanks a lot, everyone! very useful responses!
learned some stuff

User avatar
zankizuna
Veteran
Posts: 416
Joined: Fri May 04, 2012 2:20 am
Projects: Softwar
Deviantart: raseru09
itch: ZanKizuna
Location: Manilaaaaaaaa
Contact:

Re: Is it possible to use a variable when "show" ing somethi

#8 Post by zankizuna » Tue Apr 12, 2016 4:13 am

ummm...If I may ask another question...
is this possible for 'at' codes too?

like ...
$positionA=Position(xpos=0.3,ypos=0.5)
$positionB=Position(xpos=0.7,ypos=0.5)

default position =positionA
show ImageA at [position] with move

??
this doesn't work :P probably need an alternative

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Is it possible to use a variable when "show" ing somethi

#9 Post by Onishion » Tue Apr 12, 2016 4:56 am

You should be able to just type "show ImageA at postion" No brackets needed.

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Is it possible to use a variable when "show" ing somethi

#10 Post by nyaatrap » Tue Apr 12, 2016 11:56 am

You shouldn't use a statement that isn't listed on the official document.
'Position' is deprecated and no longer documented. Transform or ATL https://www.renpy.org/doc/html/atl.html should be used instead.

User avatar
zankizuna
Veteran
Posts: 416
Joined: Fri May 04, 2012 2:20 am
Projects: Softwar
Deviantart: raseru09
itch: ZanKizuna
Location: Manilaaaaaaaa
Contact:

Re: Is it possible to use a variable when "show" ing somethi

#11 Post by zankizuna » Sat Apr 16, 2016 9:51 am

oh umm... nvm about the last question :P I used a variable like this:

$variablexpos=0.25
show Something with move:
xpos variablexpos
ypos 0.4
.. yeah something like that.

Post Reply

Who is online

Users browsing this forum: Alex, nyeowmi