Getting the current dialogue string into 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
_kagire
Newbie
Posts: 4
Joined: Tue Sep 24, 2019 3:02 pm
Location: Russia ._.
Contact:

Getting the current dialogue string into a variable

#1 Post by _kagire »

I need to store current dialogue string in a variable, but I don't understand how to do that and I couldn't find any information about that anywhere. Any help, please? :c

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Getting the current dialogue string into a variable

#2 Post by RicharDann »

Probably the easiest method would be to add an action to the say screen. Then, whenever dialogue is presented to the player (by using RenPy's default dialogue system) the screen will update the variable for you. Of course it will continue to update it whenever dialogue changes, so it may not be what you want.

Code: Select all

default current_dialogue = None # a variable that will hold current dialogue

# Say screen
screen say(who, what):
    on 'show':
        action SetVariable('current_dialogue', what) #sets current_dialogue to what 
What would you be doing with this variable once it's stored?
The most important step is always the next one.

_kagire
Newbie
Posts: 4
Joined: Tue Sep 24, 2019 3:02 pm
Location: Russia ._.
Contact:

Re: Getting the current dialogue string into a variable

#3 Post by _kagire »

Oh, that easy? I was thinking about something like that, but couldn't make it work. Thanks! >_<
I'll count an amout of characters in the string, I need it for one game feature that I can't explain shortly.

_kagire
Newbie
Posts: 4
Joined: Tue Sep 24, 2019 3:02 pm
Location: Russia ._.
Contact:

Re: Getting the current dialogue string into a variable

#4 Post by _kagire »

Sorry, forgot... I need it to work with NVL mode.

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: Getting the current dialogue string into a variable

#5 Post by RicharDann »

Hmmm, to be honest I'm not very familiar with the way NVL mode works internally, but taking a look at the documentation here, I suppose this could work:

Code: Select all

screen nvl_dialogue(dialogue):

    for d in dialogue:

        window:
            id d.window_id

            fixed:
                yfit gui.nvl_height is None

                if d.who is not None:

                    text d.who:
                        id d.who_id

                text d.what:
                    id d.what_id
                    
		## Add this two lines at the end, respecting the identation
                if d.current:
                    timer .01 action SetVariable('current_dialogue', d.what)

This would cause the screen to immediately set the current_dialogue variable to the latest/current line displayed.
The most important step is always the next one.

_kagire
Newbie
Posts: 4
Joined: Tue Sep 24, 2019 3:02 pm
Location: Russia ._.
Contact:

Re: Getting the current dialogue string into a variable

#6 Post by _kagire »

It works! Thanks, again ^^

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Nozori_Games