Dynamic Style Updates for Characters During Game

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
LogarithmicEagle
Newbie
Posts: 1
Joined: Tue Jan 16, 2024 5:27 pm
Projects: Roommates
Contact:

Dynamic Style Updates for Characters During Game

#1 Post by LogarithmicEagle »

During the game, I plan on changing the style of character's text box and such based on a variable. After careful reading of the documentation, I found a way to do this using character callbacks, but I wanted to make sure that this was the best way to do that. I want to make sure my solution is "ren-pythonic" and doesn't hinder stuff like the image prediction stuff etc. I would love the thoughts of the more seasoned users of renpy. An example of my solution is below and uses character callbacks.

Code: Select all

style test_1_say_dialogue:
    color "#f00"

style test_2_say_dialogue:
    color "#0f0"

init python:
    my_bool = True

    def change_style():
        if my_bool:
            return 'test_1_say_dialogue'
        else:
            return 'test_2_say_dialogue'
    
    def change_color(event, interact=True, **kwargs):
        if event == 'begin':
            e.what_args['style'] = change_style()

            
define e = Character("Eileen", callback=change_color)
From my testing, this solution works--if I change the value of my_bool to False, then the color dynamically changes. My concern right now with this solution is that it doesn't scale the best with more characters (two functions per character). It also feels "cheaty" by changing the style using e.what_args['style'] = change_style(). I'd love any of y'all's thoughts. Thanks again ^^

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]