Ren'Py [Solved]Assign a key to a simple Label

GoldenD

Member
Sep 30, 2018
102
70
Hey,
i'm always here. Ok, i will try to do simple. The idea is simple : i can play video and i can choose Fullscreen or Windowed Movie.
If i choose windowed movie, I want to be able to switch to full screen with a key ("f" for example).
I've read what i could but nothing clear for me without a screen (renpy org and of course The Great ).
I think my problem is to not use screen or some displayable control but my goal is to do the more simple when it's possible. Ok, my "stupid" code now, clearer for you, i hope.

Python:
.../...
default isFullScreenable    = False

label start:

    #--------------------------------------------------------------------------------------------------
    #                  PLAYING MOVIE FULLSCREEN : STOP BY PLAYER ACTION - CLICK, KEYBOARD...
    #--------------------------------------------------------------------------------------------------

    menu chooseWhatYouWant:

        "Play Movie Fullscreen":

            call playMovie(True)
            scene expression "[PICTURES_LOCATIONS]home_day.png"
            speaker "Movie FullScreen Finished"

        "Play Movie resizing":

            $ isFullScreenable = True
            call playMovie()
            speaker "Movie Resizing Finished"

            .../...

        
label playMovie(isFullScreen = False):

    if isFullScreen:
            call playFullScreen()
            "Movie Fullscreen interrupted by Player"
    else:
            call playWindowMovie()
            "Playing through once, and stopping at the (faked) final frame"

            if isFullScreenable:
                $ isFullScreenable = False
                key "f" action call playFullScreen()
Of course, i obtain an error which is :

File "game/code/functions/moviePlayer.rpy", line 47: end of line expected.
key "f" action Call(playFullScreen)
Variable [isFullScreenable] is there to deactivate the F key when i'm out of my function.
 
Last edited:

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,302
15,172
If i choose windowed movie, I want to be able to switch to full screen with a key ("f" for example).
Why not let Ren'py deal with all this ? You make your movie for "full screen", and Ren'py will just resize it automatically, according to the actual size of its rendering zone.
As for the possibility to switch full screen, forget about the "f" key... It's already used by Ren'py... to switch between full screen and windowed.

Anyway, "full screen" have no sense here. Will your movie have a resolution of 1280x1024, 1920x1080, 1920x1200, or one of the many other ones ? If the screen resolution of the player isn't the same than yours, Ren'py will resize the movie anyway, even the "full screen" one. So, let it do it from the start, it will be easier.


Code:
                key "f" action call playFullScreen()
As long as I understood it, what you wanted is the screen action :
Code:
                key "f" action Call( "playFullScreen" )
 

GoldenD

Member
Sep 30, 2018
102
70
Why not let Ren'py deal with all this ? You make your movie for "full screen", and Ren'py will just resize it automatically, according to the actual size of its rendering zone.
As for the possibility to switch full screen, forget about the "f" key... It's already used by Ren'py... to switch between full screen and windowed.

Anyway, "full screen" have no sense here. Will your movie have a resolution of 1280x1024, 1920x1080, 1920x1200, or one of the many other ones ? If the screen resolution of the player isn't the same than yours, Ren'py will resize the movie anyway, even the "full screen" one. So, let it do it from the start, it will be easier.




As long as I understood it, what you wanted is the screen action :
Code:
                key "f" action Call( "playFullScreen" )

Ok AON,
first and to be sure we talk about same thing, the switch is not a toggle between "Game" windowed and full screen of course.
The goal is to display a video (800*600 or sthg else) at the center of the scene with a text story on the say_though (say_dialog) box. And for "more pleasure", the user could see this video in a more confortable size (originally videos have a 1920x1200 resolution) .
Is that clear ? (but I know i speak english like a spanish cow!)

So, i've tried this
Code:
key "f" action Call( "playFullScreen" )
but with the same issue (in fact it is a syntax i tried before).

And of course Key "F" was a sample but my first research did not show me that this key was used. I'll find another.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,302
15,172
The goal is to display a video (800*600 or sthg else) at the center of the scene with a text story on the say_though (say_dialog) box. And for "more pleasure", the user could see this video in a more confortable size (originally videos have a 1920x1200 resolution) .
Why doing this ? You'll need more time to post-process the movie, since you'll need two, and you'll complicate the code of the game for a reason that feel unnecessary. All the players will goes for the "full screen" option, since it's the one that give the best result visually speaking. And it don't prevent you to have dialogs during the movie, nor to effectively enjoy it.

But well :
Python:
# You define the movie as displayable
image myMovie = Movie(play="ONE MOVIE")

# Everything will be handled by a screen displaying the movie
screen moviePlayer( movie, fs=False ):

    default fullScreen = fs

    add movie:
        xalign 0.5 yalign 0.5
        # The magic is here. If the /fullScreen/ flag is False, Ren'py
        # will automatically scale the movie to fit the size given to
        # the display box. Else it will display the movie at its original
        # size.
        # Anyway this size will always be weighted by the effective
        # size of its rendering window.
        if fullScreen is False:
            # Ren'py will automatically scale the movie to fit the size of
            # the available display box.
            size( 800, 600 )

    # And the key will be local to the screen, switching the said flag.
    key "f" action SetScreenVariable( "fullScreen", not fullScreen )


label whatever:
    
    # You start the movie.
    # /!\ that the name of the displayable MUST be quoted.
    show screen moviePlayer( "myMovie" )
    # Do whatever you want when it play, including dialog, 
    # menu, and all ; you can even /jump/ and /call/ if you want.
    [...]
    # Then when it's finished, you hide the screen to stop 
    # the movie.
    hide screen moviePlayer
    [...]

    # You can also force full screen from start
    show screen moviePlayer( "anotherMovie", fs=True )
    [...]
    hide screen moviePlayer

So, i've tried this
Code:
key "f" action Call( "playFullScreen" )
but with the same issue (in fact it is a syntax i tried before).
It give you a "end of line expected" error ?

Hm... When thinking deeper about this, it's neither the error you should have with the initial key "f" action call playFullScreen() ; the error should be about the invalidity of the child for this statement.

And here come the sudden realization. Your code is :
Code:
label playMovie(isFullScreen = False):
[...]
                key "f" action call playFullScreen()
naively, and wrongly, read it as a screen at first.
[Side note: Remember, when debugging, never jump directly to the faulty line, always take care of the context :( ]

It's normal that Ren'py complain, is a screen statement, and you use it in a label.
 
  • Like
Reactions: t727 and GoldenD

GoldenD

Member
Sep 30, 2018
102
70
Why doing this ? You'll need more time to post-process the movie, since you'll need two, and you'll complicate the code of the game for a reason that feel unnecessary. All the players will goes for the "full screen" option, since it's the one that give the best result visually speaking. And it don't prevent you to have dialogs during the movie, nor to effectively enjoy it.

But well :
Python:
# You define the movie as displayable
image myMovie = Movie(play="ONE MOVIE")

# Everything will be handled by a screen displaying the movie
screen moviePlayer( movie, fs=False ):

    default fullScreen = fs

    add movie:
        xalign 0.5 yalign 0.5
        # The magic is here. If the /fullScreen/ flag is False, Ren'py
        # will automatically scale the movie to fit the size given to
        # the display box. Else it will display the movie at its original
        # size.
        # Anyway this size will always be weighted by the effective
        # size of its rendering window.
        if fullScreen is False:
            # Ren'py will automatically scale the movie to fit the size of
            # the available display box.
            size( 800, 600 )

    # And the key will be local to the screen, switching the said flag.
    key "f" action SetScreenVariable( "fullScreen", not fullScreen )


label whatever:
   
    # You start the movie.
    # /!\ that the name of the displayable MUST be quoted.
    show screen moviePlayer( "myMovie" )
    # Do whatever you want when it play, including dialog,
    # menu, and all ; you can even /jump/ and /call/ if you want.
    [...]
    # Then when it's finished, you hide the screen to stop
    # the movie.
    hide screen moviePlayer
    [...]

    # You can also force full screen from start
    show screen moviePlayer( "anotherMovie", fs=True )
    [...]
    hide screen moviePlayer



It give you a "end of line expected" error ?

Hm... When thinking deeper about this, it's neither the error you should have with the initial key "f" action call playFullScreen() ; the error should be about the invalidity of the child for this statement.

And here come the sudden realization. Your code is :
Code:
label playMovie(isFullScreen = False):
[...]
                key "f" action call playFullScreen()
naively, and wrongly, read it as a screen at first.
[Side note: Remember, when debugging, never jump directly to the faulty line, always take care of the context :( ]

It's normal that Ren'py complain, is a screen statement, and you use it in a label.
What to say ?
A great thanks for your patience and cooperation.
I'm not a friend of renpy's statement nor displayables !
I'll try this later.
Thanks again.
 

GoldenD

Member
Sep 30, 2018
102
70
Why doing this ? You'll need more time to post-process the movie, since you'll need two, and you'll complicate the code of the game for a reason that feel unnecessary. All the players will goes for the "full screen" option, since it's the one that give the best result visually speaking. And it don't prevent you to have dialogs during the movie, nor to effectively enjoy it.

But well :
Python:
# You define the movie as displayable
image myMovie = Movie(play="ONE MOVIE")

# Everything will be handled by a screen displaying the movie
screen moviePlayer( movie, fs=False ):

    default fullScreen = fs

    add movie:
        xalign 0.5 yalign 0.5
        # The magic is here. If the /fullScreen/ flag is False, Ren'py
        # will automatically scale the movie to fit the size given to
        # the display box. Else it will display the movie at its original
        # size.
        # Anyway this size will always be weighted by the effective
        # size of its rendering window.
        if fullScreen is False:
            # Ren'py will automatically scale the movie to fit the size of
            # the available display box.
            size( 800, 600 )

    # And the key will be local to the screen, switching the said flag.
    key "f" action SetScreenVariable( "fullScreen", not fullScreen )


label whatever:
  
    # You start the movie.
    # /!\ that the name of the displayable MUST be quoted.
    show screen moviePlayer( "myMovie" )
    # Do whatever you want when it play, including dialog,
    # menu, and all ; you can even /jump/ and /call/ if you want.
    [...]
    # Then when it's finished, you hide the screen to stop
    # the movie.
    hide screen moviePlayer
    [...]

    # You can also force full screen from start
    show screen moviePlayer( "anotherMovie", fs=True )
    [...]
    hide screen moviePlayer



It give you a "end of line expected" error ?

Hm... When thinking deeper about this, it's neither the error you should have with the initial key "f" action call playFullScreen() ; the error should be about the invalidity of the child for this statement.

And here come the sudden realization. Your code is :
Code:
label playMovie(isFullScreen = False):
[...]
                key "f" action call playFullScreen()
naively, and wrongly, read it as a screen at first.
[Side note: Remember, when debugging, never jump directly to the faulty line, always take care of the context :( ]

It's normal that Ren'py complain, is a screen statement, and you use it in a label.
Hi AON and all the team of course,
finally and after some tests i decide to re-open this thread.

First, a second explanation of my "movie fullscreen wish", hoping it will be clearer than before : i don't search a "renpy" fullscreen like with the F key does, i want a movie and only movie fullscreen calling "renpy.movie_cutscene". Is it necessary, is it appropriate, i don't know, it's more my way to understand renpy capacities.

So and second point, i understood i apparently need a screen statement to assign key, but i tried some others key ("9", "K_9"..) without success and i think it's movie fault because movie understand key use like a stop reading order.

Third, after tests, it reveals than screen is not a good solution from my point of view because it's sensitive to Hide Key for example and when you just want to hide dialog, the screen is hidden too. I made many tests with modal (which seems lock all keys but "H", zorder...) i didn't find a good solution.

On the contrary, the Label i used at first seems to be a solution (certainly not the best) for no bad effects of H key, but in the same time, i can't assign new key. I have to think maybe about addind a button (maybe invisible ?) calling renpy.movie_cutscene.

I stop here because i'm not sure your head is able to read and understand this great english which is mine. And thanks again for your patience.

Kiss at all :p(y):coffee:
 

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,690
Hi AON and all the team of course,
finally and after some tests i decide to re-open this thread.

First, a second explanation of my "movie fullscreen wish", hoping it will be clearer than before : i don't search a "renpy" fullscreen like with the F key does, i want a movie and only movie fullscreen calling "renpy.movie_cutscene". Is it necessary, is it appropriate, i don't know, it's more my way to understand renpy capacities.

So and second point, i understood i apparently need a screen statement to assign key, but i tried some others key ("9", "K_9"..) without success and i think it's movie fault because movie understand key use like a stop reading order.

Third, after tests, it reveals than screen is not a good solution from my point of view because it's sensitive to Hide Key for example and when you just want to hide dialog, the screen is hidden too. I made many tests with modal (which seems lock all keys but "H", zorder...) i didn't find a good solution.

On the contrary, the Label i used at first seems to be a solution (certainly not the best) for no bad effects of H key, but in the same time, i can't assign new key. I have to think maybe about addind a button (maybe invisible ?) calling renpy.movie_cutscene.

I stop here because i'm not sure your head is able to read and understand this great english which is mine. And thanks again for your patience.

Kiss at all :p(y):coffee:
To prevent a screen from being hidden you can add this to it:
Python:
screen my_keys:
    key "h" action NullAction()
Source:
 
  • Like
Reactions: anne O'nymous

GoldenD

Member
Sep 30, 2018
102
70
To prevent a screen from being hidden you can add this to it:
Python:
screen my_keys:
    key "h" action NullAction()
Source:
Hi mgomez,
nice try. What you propose works but it disables completely H key. So i just want to hide the screen say.
But ok, i notice this option.
Thank you for your participation. (y)
 
  • Like
Reactions: Porcus Dev

Porcus Dev

Engaged Member
Game Developer
Oct 12, 2017
2,582
4,690
Hi mgomez,
nice try. What you propose works but it disables completely H key. So i just want to hide the screen say.
But ok, i notice this option.
Thank you for your participation. (y)
I'm not sure what you want to do...

If you want to hide the text before a screen or a video, you can use this:
Python:
label your_label:
    ....
    window hide
    ## play your movie
    ....
And if you want to hide the text inside a screen by pressing a key (which is strange since inside one of your screens there won't be the "say" screen), maybe this can help (I haven't tried it):
Python:
screen my_keys:
    key "h" action Hide("say")
 
  • Like
Reactions: anne O'nymous

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,302
15,172
On the contrary, the Label i used at first seems to be a solution (certainly not the best) for no bad effects of H key, but in the same time, i can't assign new key.
This will never be the solution, because it will always restart the movie each time you'll change label. Passing by a screen playing the movie is the only way to have the behavior you want.


I'm not sure what you want to do...
From what I understood, he want the h key to works, but when the movie is playing the said key should just hide the "say" screen, not both it and the screen playing the movie.

Therefore, the solution is in the said screen. But a simple Hide( "say" )/Show( "say" ) would not works ; the "say" screen ask for parameters that you can't provide because you can't guess them.

This imply that the best way to do is to tweak the said "say" screen, to make its display depend of a flag :
Python:
# The flag that will decide if the /say/ screen should show
# its content, or not
default sayIsHidden = False

# /!\ WARNING /!\
# Depending of the version of Ren'Py, the header can change
screen say(who, what):

    style_prefix "say"

    # You can't just use the flag to display or not the content
    # of the screen, because this screen is expected to return
    # something. Therefore, instead of hiding it by not displaying
    # its content, display the said content outside of Ren'py
    # display window.
    frame style "empty":
        if sayIsHidden is True:
            ypos config.screen_height + 100

        # Here, put the rest of what is already in this screen
        # But remember that it should have *one* level more
        # of identation
        if what == "":
            text what id "what" style "invisible"
        [...]
And in the "moviePlayer" screen (see my previous comment), you redefine the behavior of the "h" key by adding this :
Code:
        key "hide_windows" action SetVariable( "sayIsHidden", not sayIsHidden )
It will switch the value of the sayIsHidden flag we created above, and so switch between the shown and hidden "say" screen.
Note that I haven't directly used the key as trigger, because "h" isn't the only way to hide the screen. Instead I used the nickname used by Ren'py to store the keys that hide the screen, which guaranty that you'll never forget one, even if Ren'py changed this, or if the user did it.

But it's still not enough. With this code, if the player decide to hide the "say" screen, it will stay hidden until it press the right key once again. It's not a good design for an user interface, and anyway the player wouldn't know when he have to press the key again, because he can't know when the movie will hide.
One solution is to force the flag to True after hiding the "moviePlayer" screen :
Code:
label whatever:
    show screen moviePlayer( "myMovie" )
    "Some text goes here"
    [...]
    hide screen moviePlayer
    $ sayIsHidden = False
But it's not a good solution, because at anytime you can forgot to add this line, and you'll break all your game.
Instead, make this change done directly in the "moviePlayer" screen :
Code:
        on "hide" action SetVariable( "sayIsHidden", False )
The screen statement is triggered when an "event" (here "hide") happen to the screen. Therefore, this line set the value of our flag at False when the screen is hidden. It's the same than the $ sayIsHidden = False line above, except that it's now automatic, so you can't forget it.
 
Last edited:
  • Love
Reactions: Porcus Dev

GoldenD

Member
Sep 30, 2018
102
70
This will never be the solution, because it will always restart the movie each time you'll change label. Passing by a screen playing the movie is the only way to have the behavior you want.




From what I understood, he want the h key to works, but when the movie is playing the said key should just hide the "say" screen, not both it and the screen playing the movie.

Therefore, the solution is in the said screen. But a simple Hide( "say" )/Show( "say" ) would not works ; the "say" screen ask for parameters that you can't provide because you can't guess them.

This imply that the best way to do is to tweak the said "say" screen, to make its display depend of a flag :
Python:
# The flag that will decide if the /say/ screen should show
# its content, or not
default sayIsHidden = False

# /!\ WARNING /!\
# Depending of the version of Ren'Py, the header can change
screen say(who, what):

    style_prefix "say"

    # You can't just use the flag to display or not the content
    # of the screen, because this screen is expected to return
    # something. Therefore, instead of hiding it by not displaying
    # its content, display the said content outside of Ren'py
    # display window.
    frame style "empty":
        if sayIsHidden is True:
            ypos config.screen_height + 100

        # Here, put the rest of what is already in this screen
        # But remember that it should have *one* level more
        # of identation
        if what == "":
            text what id "what" style "invisible"
        [...]
And in the "moviePlayer" screen (see my previous comment), you redefine the behavior of the "h" key by adding this :
Code:
        key "hide_windows" action SetVariable( "sayIsHidden", not sayIsHidden )
It will switch the value of the sayIsHidden flag we created above, and so switch between the shown and hidden "say" screen.
Note that I haven't directly used the key as trigger, because "h" isn't the only way to hide the screen. Instead I used the nickname used by Ren'py to store the keys that hide the screen, which guaranty that you'll never forget one, even if Ren'py changed this, or if the user did it.

But it's still not enough. With this code, if the player decide to hide the "say" screen, it will stay hidden until it press the right key once again. It's not a good design for an user interface, and anyway the player wouldn't know when he have to press the key again, because he can't know when the movie will hide.
One solution is to force the flag to True after hiding the "moviePlayer" screen :
Code:
label whatever:
    show screen moviePlayer( "myMovie" )
    "Some text goes here"
    [...]
    hide screen moviePlayer
    $ sayIsHidden = False
But it's not a good solution, because at anytime you can forgot to add this line, and you'll break all your game.
Instead, make this change done directly in the "moviePlayer" screen :
Code:
        on "hide" action SetVariable( "sayIsHidden", False )
The screen statement is triggered when an "event" (here "hide") happen to the screen. Therefore, this line set the value of our flag at False when the screen is hidden. It's the same than the $ sayIsHidden = False line above, except that it's now automatic, so you can't forget it.
Ok Misters,
i notice all your technicals suggestions and ideas that help me to improve . For now, i think the Label does the job even if i think it's not the good way (or method) and i'm sure than if AOn says
This will never be the solution
, he knows what he’s talking about.
But for now, my renpy's newbie's level and my bad understanding of displayables, difference between screens, scenes... is the principal reason that do not allow me to choose a particular way.
I know there's a solution and that's ok for me, for now. When i'll kow better renpy, i think i'll choose the right way with your help.

To tell you the truth, my project(s) is to rewrite some Qsp Games. I already spent three months (15hours/day) to rewrite Family Life in Qsp (Qsp to Qsp) because i thought the story was good but impossible to play and to understand the logical. But Qsp "IDE" himself is bugging, updates are difficult without replay from beginning even if i found a solution and Qsp seems dead. Oh, and i've no time anymore to learn russian !
So it's why i post some questions about renpy to know if it's possible to use it in this way.

So next step for me : arrays, list, class or something like that if renpy proposes this type of solution.

Thanks a lot guys, see you soon !!!! (y)
 
  • Like
Reactions: Porcus Dev