Ren'Py How to get current screen name?

ZLZK

Member
Modder
Jul 2, 2017
295
794
I want to be able to save current screen name (any screen in any game)
to a variable and display it in another screen, but I wasn't able to do it.

I know there is renpy.current_screen(),
but it returns None when I try to use it.

I have done something like this:
You don't have permission to view the spoiler content. Log in or register now.
It kind of works, but it's not what I'm looking for.
I want to get exact screen and not to look for it.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,608
2,256
Do you have control over the screens you are trying to capture the names of?

That is... are you trying to write some sort of generic addon to attach to other people's games and do things with their screens?
... or is it screens which you yourself have written (or at least can alter, in the case of RenPy's own predefined screens)?

If it's your own screens, a kludge like might work for you. Each time your screen is shown, use to store the name of the latest screen.

If you're writing something a lot more generic, then you're going to have to go into the RenPy internals. I'm thinking perhaps about taking apart ./renpy/common/_developer/inspector.rpym, which is the Displayable Inspector (SHIFT+I) developer menu. It shows the current screen name amongst other data when invoked. So it should get you where you are trying to get to.
 
  • Like
Reactions: ZLZK

ZLZK

Member
Modder
Jul 2, 2017
295
794
Do you have control over the screens you are trying to capture the names of?

That is... are you trying to write some sort of generic addon to attach to other people's games and do things with their screens?
... or is it screens which you yourself have written (or at least can alter, in the case of RenPy's own predefined screens)?

If it's your own screens, a kludge like might work for you. Each time your screen is shown, use to store the name of the latest screen.

If you're writing something a lot more generic, then you're going to have to go into the RenPy internals. I'm thinking perhaps about taking apart ./renpy/common/_developer/inspector.rpym, which is the Displayable Inspector (SHIFT+I) developer menu. It shows the current screen name amongst other data when invoked. So it should get you where you are trying to get to.
I have done this mod.
It requires screen names to work.
I can't possibly check for every Ren'Py game,
so I want to build in screen that show you active screen name,
and let's you save it. (I think I can manage writing to files.)
Also my config works real time, so you could see changes right away.

I will later figure out what Displayable Inspector is.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,608
2,256
I will later figure out what Displayable Inspector is.

As long as you can access the (either by running a game from then RenPy Launcher or having config.developer = True set)... you should be able to access the Displayable Inspector in much the same way you can access the Console.

SHIFT+O = Console
SHIFT+I = Displayable Inspector
SHIFT+D = Developer Menu
etc.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,971
16,228
I know there is renpy.current_screen(),
but it returns None when I try to use it.
Because it don't do what you expect it to do.

It's used to know what screen is using you, therefore it's only relevant inside an user defined displayable and used screens:
Python:
screen myBase():
    tag test
    use insider

screen myAlternate():
    tag test
    use insider

screen insider():
    if renpy.current_screen().screen_name == ( "myBase", ):
        text "I'm used by 'myBase'" xalign 0.5 yalign 0.5
    else:
        text "I'm used by 'myAlternate'" xalign 0.5 yalign 0.5

label start:
    show screen myBase
    "Press a key please"
    show screen myAlternate
    "END"
Outside of a screen it have no value because its value have no meaning ; you can perfectly have 50 screens displayed at the same time, what mean that there's no "current screen".



I'm thinking perhaps about taking apart ./renpy/common/_developer/inspector.rpym, which is the Displayable Inspector (SHIFT+I) developer menu. It shows the current screen name amongst other data when invoked.
It show all the currently displayed screens, through (once unabstracted)renpy.display.render.screen_render.main_displayables_at_point( x, y, st, at ) (the arguments have the same values that with transforms and displayable events.
But it can't tell what is the "main screen", just what is the relevant screen right now. It can do it because the inspector is called directly from the interaction part of the screen, and therefore it know the mouse coordinates.

This mean that to get the name of all the screens currently shown you can use this:
Python:
    def currentScreens():
        lst = []
        for v in renpy.display.render.screen_render.main_displayables_at_point( 0, 0, 0, 0 ):
            if isinstance( v[3], renpy.display.screen.ScreenDisplayable ):
                lst.append( " ".join( v[3].screen_name ) )
        return lst
But to know the name of the relevant screen you have to use a custom displayable, that will catch the right key combination, then call "main_displayables_at_point" with the current mouse coordinates ; starting and current times are probably none relevant for this particular use.
 
  • Like
Reactions: ZLZK

ZLZK

Member
Modder
Jul 2, 2017
295
794
It's used to know what screen is using you, therefore it's only relevant inside an user defined displayable and used screens:
I expected as much since I'm using it in my mod correctly.

It show all the currently displayed screens, through (once unabstracted)renpy.display.render.screen_render.main_displayables_at_point( x, y, st, at ) (the arguments have the same values that with transforms and displayable events.
But it can't tell what is the "main screen", just what is the relevant screen right now. It can do it because the inspector is called directly from the interaction part of the screen, and therefore it know the mouse coordinates.
Right before your post I have done something like this:
Python:
        x, y = renpy.display.draw.get_mouse_pos()
        
        for depth, width, height, d in renpy.display.interface.surftree.main_displayables_at_point(x, y, renpy.config.layers):
            if isinstance(d, renpy.display.screen.ScreenDisplayable):
                screen_name = d.screen.name[0]
                break
        else:
            screen_name = ""
But I don't know if this will work in all Ren'Py versions,
and I even need to come with a way to detect top screen.
This doesn't look any better than my first attempt.
 

ZLZK

Member
Modder
Jul 2, 2017
295
794
I guess it's pretty solid after all.
It's working for me in older Ren'Py.

I have ended up with this.
I guess it's good enough.
 
Last edited: