How to define an Image using a VARIABLE

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
badani
Newbie
Posts: 2
Joined: Mon Jul 25, 2016 8:42 am
Location: Lima, Peru
Contact:

How to define an Image using a VARIABLE

#1 Post by badani »

I've got eight colour strips (strip0 through strip7) whose filenames are defined in the corresponding variables (e.g.: strip0 = "thiscolour.png") whih may contain different colours according to what the user selects meaning each of the eight strips may have a DIFFERENT colour each time the game runs.
Is there a way to define my images using the Variable Name…?
I've already tried:

image c0 = strip0

image c0 = [strip0]

image c0 = [strip0!t]

none of which works (and, as the colour will be variable I can not use image c0 = "thiscolour.png"). Please help!

Thanks in advance…!

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: How to define an Image using a VARIABLE

#2 Post by Alex »

I don't know what you trying to achieve, but this might help you

Code: Select all

image strip0 = "thiscolour_0.png"
image strip1 = "thiscolour_1.png"
image strip2 = "thiscolour_2.png"

screen color_scr(x):
    add x 
    
label start:
    "?"
    $ color_to_show = renpy.random.choice(("strip0", "strip1", "strip2"))
    scene expression color_to_show
    "!"
    scene black
    "..."
    show screen color_scr(x=color_to_show)
    "?!"
https://www.renpy.org/doc/html/displayi ... -statement
https://www.renpy.org/doc/html/other.html#renpy-random
https://www.renpy.org/doc/html/screens.html

Also, check https://www.renpy.org/doc/html/displaya ... splayables
viewtopic.php?f=51&t=19063

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: How to define an Image using a VARIABLE

#3 Post by xavimat »

I certainly would use a dynamic displayable (already linked by Alex)
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

User avatar
badani
Newbie
Posts: 2
Joined: Mon Jul 25, 2016 8:42 am
Location: Lima, Peru
Contact:

THANK YOU!

#4 Post by badani »

Thanks a lot! I'm afraid I'm still quite green in Ren'Py and Python... but I'm interested in learning and you've really helped!

Post Reply

Who is online

Users browsing this forum: No registered users