Pass argument to show image

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
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Pass argument to show image

#1 Post by TellerFarsight »

I'm trying to have a label that shows an image, but I want to have which image it is be dependent on the argument of the label (so I can reuse it).
The simplified version looks like this:

Code: Select all

label portrait(character_name):
    show "images/"+ "[character_name]" +"_image.png" at my_transform
the character_name that is passed into this IS NOT a string, but is an object.
As in Eileen, not "Eileen" because I need to later call on attributes like Eileen.hair_color
(I could solve this problem by making it a string, or by making the image an attribute of the object, but I'm trying to make the code more efficient and I want to know if there's a way to this.)

I've also tried making it a variable:

Code: Select all

label portrait(character_name):
    show [character_name]_image at my_transform
but in both cases, it returns the error "expected 'image_name_component' not found"
So, is there a way to turn an object name to a string, or pass it into the name of a variable?
Are the square brackets even used for this ever or did I just make it up?
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

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

Re: Pass argument to show image

#2 Post by xela »

Like what we're doing? Support us at:
Image

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: Pass argument to show image

#3 Post by Remix »

If you are passing in an object you would need the character_object.name (or character_object.image may be better if you set that tag the same as the image name part (better = would work with dynamic characters as well))

show expression "images/[character_object.image]_image.png" as some_alias at my_transform
"words"
hide some_alias
Frameworks & Scriptlets:

User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: Pass argument to show image

#4 Post by TellerFarsight »

That works exactly as I hoped. Is there a way to use a variable name instead of "images/[character_object.image]_image.png"? I want to know if I can use image manipulators on top of this, like FactorScale, and if I apply that directly to the expression it says it can no longer find the .png file. Also if the image is blinking, or if I want to tailor the positioning for the image (so I don't need to have the transform change based on which character I pass in).
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

Post Reply

Who is online

Users browsing this forum: Galo223344, Google [Bot], Majestic-12 [Bot]