Testing if screen/image 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
User avatar
computistxyz
Regular
Posts: 58
Joined: Thu Jul 10, 2014 8:35 am
Github: sjgriffiths
Location: Coventry/Norwich, UK
Contact:

Testing if screen/image is shown

#1 Post by computistxyz »

Is there a function which returns True/False based on whether a specified screen/image is currently being shown, for use with if statements? I distinctly remember such a thing but can't for the life of me find official reference to it.

If not, how might I define this function(s) myself?
computer scientist | programmer | game developer | writer | editor/proofreader

Check out my technical blog, computist.xyz

User avatar
shivanshs9
Regular
Posts: 54
Joined: Sun Jul 20, 2014 1:59 pm
Projects: The Destiny(http://thedestiny-cxz.blogspot.com)
Organization: Cyber-X-Zone
Location: India
Contact:

Re: Testing if screen/image is shown

#2 Post by shivanshs9 »

There is actually a function, but sadly(and for an unknown reason) it isn't documented...

Code: Select all

renpy.current_screen()
This function is used by the FileAction function to save or load depending on the current screen. Here's how you need to use it:

Code: Select all

if renpy.current_screen().screen_name[0] == "name_of_screen":
    # Do Something!
"Destiny is a no matter of chance
It is a matter of choice
It is not a thing to be waited for
It is a thing to be achieved..."

-William Jennings Bryan
If you can dream and not make dreams your master;
If you can think and not make thoughts your aim,
If you can meet with Triumph and Disaster;
And treat those two impostors just the same,
Only then can you ever win against yourself...

User avatar
computistxyz
Regular
Posts: 58
Joined: Thu Jul 10, 2014 8:35 am
Github: sjgriffiths
Location: Coventry/Norwich, UK
Contact:

Re: Testing if screen/image is shown

#3 Post by computistxyz »

shivanshs9 wrote:There is actually a function, but sadly(and for an unknown reason) it isn't documented...

Code: Select all

renpy.current_screen()
This function is used by the FileAction function to save or load depending on the current screen. Here's how you need to use it:

Code: Select all

if renpy.current_screen().screen_name[0] == "name_of_screen":
    # Do Something!
Aha! That's exactly what I was thinking of for screens, cheers!

Out of curiosity, is there a different way of testing whether any particular image/displayable is currently being shown, or, equivalently, perhaps whether there is any image/displayable currently being shown which possesses a particular name?
computer scientist | programmer | game developer | writer | editor/proofreader

Check out my technical blog, computist.xyz

User avatar
shivanshs9
Regular
Posts: 54
Joined: Sun Jul 20, 2014 1:59 pm
Projects: The Destiny(http://thedestiny-cxz.blogspot.com)
Organization: Cyber-X-Zone
Location: India
Contact:

Re: Testing if screen/image is shown

#4 Post by shivanshs9 »

Well, sadly, I am not aware of a similar function for displayables/images...
"Destiny is a no matter of chance
It is a matter of choice
It is not a thing to be waited for
It is a thing to be achieved..."

-William Jennings Bryan
If you can dream and not make dreams your master;
If you can think and not make thoughts your aim,
If you can meet with Triumph and Disaster;
And treat those two impostors just the same,
Only then can you ever win against yourself...

User avatar
computistxyz
Regular
Posts: 58
Joined: Thu Jul 10, 2014 8:35 am
Github: sjgriffiths
Location: Coventry/Norwich, UK
Contact:

Re: Testing if screen/image is shown

#5 Post by computistxyz »

I've realised that for my usage, checking screens is all I have to do anyway, so no worries on the image/displayable part.

However, I've run into a problem involving renpy.current_screen().screen_name. Let's say I'm testing to see if the say screen is currently shown. If I have this:

Code: Select all

if renpy.current_screen().screen_name[0] == "say":
    text "say is shown"
else:
    text "say is not shown"
in another overlay screen, it only ever report say as not shown, even when the textbox is clearly visible and dialogue is occurring. It only seems to report in the positive when the above code is in the say screen itself, as though current_screen() only has the scope of the screen that bit of code is actually being called from.

How can I do a global test for any instance of a given screen from any other part of code?
computer scientist | programmer | game developer | writer | editor/proofreader

Check out my technical blog, computist.xyz

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]