How to call function everytime the say screen is shown?

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
Perik
Newbie
Posts: 14
Joined: Mon Mar 08, 2021 4:33 am
Contact:

How to call function everytime the say screen is shown?

#1 Post by Perik »

Hi!

What I want to do is something like this:

Code: Select all

label Interview_1:
       Hi there!
  	$id_of_the_text_line = 1
       $add_message()
       Hello
       $id_of_the_text_line = 2
       $add_message()
       Goodbye
       $id_of_the_text_line = 3
       $add_message()
        ​
When the text is shown I want to change variable and run function. I was thinking about calling function from say screen but as we know it won't work since it's updating far more then once.
I can get id of the line via renpy.get_return_stack() but I can't figure how to call add_message function only once. Any ideas?
Last edited by Perik on Thu Jan 20, 2022 2:21 pm, edited 1 time in total.

User avatar
m_from_space
Miko-Class Veteran
Posts: 939
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: How to call function everytime the say screen is shown?

#2 Post by m_from_space »

I don't quite get your question. Inside a label the "add_message()" function will only be called once when you call it. What exactly is your goal here regarding the ID's and the function?

If it's about setting the variable and calling the function without having the player to click first, you can do something like:

Code: Select all

label interview_1:
	"Hello!{nw}"
	$ id = 1
	$ addMessage()
	extend ""
	...
But if "addMessage()" doesn't really interact with the say screen, then you can also just call it right before saying "Hello!".

User avatar
m_from_space
Miko-Class Veteran
Posts: 939
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: How to call function everytime the say screen is shown?

#3 Post by m_from_space »

I tried something out, what you could do is the following, but there might be cases where it's not working properly, especially if you use "extend" stuff. So far, for every line of text your character is speaking, the function is only called once and the id is increasing. You could keep track of it via another screen that shows the ID in the top left corner.

Code: Select all

default lastline = "\n"

screen say(who, what):
	on "show" action If (what != lastline, [SetVariable("lastline", what),SetVariable("id", id+1),Function(addMessage)])
	...

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], piinkpuddiin