[SOLVED, with a question remaining] Use variable to set side image mood

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
opaopa13
Newbie
Posts: 13
Joined: Mon Nov 20, 2017 9:25 pm
Contact:

[SOLVED, with a question remaining] Use variable to set side image mood

#1 Post by opaopa13 »

I'd like to be able to use a variable to determine what expression a character has for a particular line, and I've been unable to determine how to do this. Basically, what I'd love is to be able to do something like this:

Code: Select all

$ mood = "happy"
zoe [mood] "Look at my face and tell me how you think I feel."
or

Code: Select all

$ mood = "happy"
$ zoe("Look at my face and tell me how you think I feel." tag=mood)
Or anything like that! As long as I can use the value of the variable to determine what image to use without having to set up a giant if-elif-elif-elif-elif-else block, I'm happy.

For bonus points, this would be even cooler:

Code: Select all

$ mood1 = "happy"
mood2 = "grinning"
zoe [mood1] "Look at my face and {nw}"
extend [mood2] "tell me how you think I feel."
...although this one is even trickier, since I haven't seen a Python equivalent for extend. I know I can use the {fast} tags to replicate this behavior without "extend," but that gets cumbersome when I'd like to do multiple face changes per line. Being able to leverage extend would be much cleaner.

Thank you very much for any help you can provide! I've taken a look at the docs (and even the renpy library source code) and not been able to figure this one out.

opaopa13
Newbie
Posts: 13
Joined: Mon Nov 20, 2017 9:25 pm
Contact:

Re: [SOLVED, with a question remaining] Use variable to set side image mood

#2 Post by opaopa13 »

I realized that there's an easy way around this: use a dynamic image. Instead of "how do I dynamically invoke an image tag with the value of a variable," I can replace my question with, "how do I dynamically set a filepath the value of a variable." And that's easy to answer:

Code: Select all

image side zoe dynamic = DynamicImage("zoe_[expression].png")

$ expression = happy
zoe dynamic "Look at my face and tell me how you think I feel."
While this works for the particular problem I'd run into, I'd still like to know the Python statement equivalent of this:

Code: Select all

zoe happy "I'm glad to hear it!"
Presumably, it looks something like this:

Code: Select all

$ zoe("I'm glad to hear it!", ???="happy")
...but I haven't been able to figure out what ??? should be! If anyone could answer that question, I'd appreciate it. It'd still be useful!

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: [SOLVED, with a question remaining] Use variable to set side image mood

#3 Post by Remix »

When you call
zoe("I'm glad to hear it!", interact=False)
(the same as renpy.say( zoe, "I'm glad to hear it!", interact=False) btw)
it is effectively passing the parameters to the __call__ method of the Character class.
As those methods do not raise any parameter to the global or store scope and do not appear to set/adjust any callback attribute values it would seem to be impossible (short of overloading the ADVCharacter or somesuch class)

If you did want to test, maybe try (as a start concept):

Code: Select all

screen show_data( arg ):
    text "[arg]" # .replace('{','{{').replace('[','[[')

init python:
    def char_cb( *args, **kwargs ):
        renpy.show_screen( 'show_data', [ args, kwargs ] )
e = Character("Eileen", callback=char_cb)
(overly simplistic and typed on the fly, so likely needs debug and certainly needs extending - it might let you see what a callback receives though)
Frameworks & Scriptlets:

opaopa13
Newbie
Posts: 13
Joined: Mon Nov 20, 2017 9:25 pm
Contact:

Re: [SOLVED, with a question remaining] Use variable to set side image mood

#4 Post by opaopa13 »

Ah, I see what you mean -- it seems strange to me that there's a functionality in the "RenPy language" (if that's the appropriate term for statements like zoe happy "I'm happy!") that isn't exposed in the Python function. I might play around with this -- for now, I have the functionality I need.

Thank you!

Post Reply

Who is online

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