Ren'Py Choice menu using Images ?

-DEV-Phil-

Newbie
Game Developer
Jan 14, 2021
95
343
Hi everyone,

I want to ask a question about adding imagebuttons to my Ren'Py game when playing a video in-game. Specifically, I want to use one button to change the camera angle and play a different video, and another button to jump to the next label.

I don't want this to be a standard menu since I want to use it in most of the movie scenes to change the camera view. That's why I was thinking about creating a menu with image buttons to achieve this.


Like that: Image0125.png

I was thinging about something like that:

Code:
label scene_view001:
scene videoxy
menu:

         "the image button1":
jump scene_view002
"the image button2":
          jump after_scene_view001
However, I have been struggling with getting it to work for hours.
I am not a programmer, and I am just doing this project for fun, so please don't be too harsh on me.

If anyone has any suggestions or advice on how to make this work, I would greatly appreciate it. Thank you in advance!


Best regards and many thanks in advance
Phil
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,620
15,601
I don't want this to be a standard menu since I want to use it in most of the movie scenes to change the camera view. That's why I was thinking about creating a menu with image buttons to achieve this.
If you don't want it to be a standard menu, why are you trying to make it a standard menu ?

What you need is just a screen with image buttons, and to use the arguments passed to this screen to define what the buttons will do.

But like it would be in fact a bit more complicated that way, here's a full movie player. It take charge of the buttons and also of displaying the movie itself:
Python:
screen moviePlayer( cameras ):

    # Just to be sure it will be on top of your possible User Interface
    zorder 10

    # Store the movie actually selected.
    # Always use the first one defined as default.
    default movie = cameras[0][0]

    # Show the actually selected movie, centered
    add movie xalign 0.5 yalign 0.5

    frame:
        # Or any style you want to apply
        style "empty"

        # Position it at top right of the screen
        ypos 0   xalign 1.0

        # Display horizontally.
        #  /!\ MUST be after the style, this permit to apply style that normally
        # wouldn't apply to hbox /!\
        has hbox

        # For all the defined cameras
        for ( file, name ) in cameras:

            # Display a button.
            vbox:
                # Firstly the button itself
                imagebutton:
                    auto "change_%s.png"
                    # that will change the selected movie.
                    action SetScreenVariable( "movie", file )
                # Then the name for this camera.
                text "[name]"

        # Then display the "continue button"
        vbox:
            imagebutton:
                auto "advance_%s.png"
                # that will simply close the screen.
                action Return()
            text "Continue"

# Define all your movies
image movie1 = Movie( play="movies/whatever.webm" )
image movie2 = Movie( play="movies/whatever else.webm" )

label whatever:

    # Call the movie player, providing it tuples for all the movie playable.
    # Each tuple being the name of the movie and the label of the camera.
    call screen moviePlayer( [ ( "movie1", "side view" ), ( "movie2", "POV" ) ] )

    "END"

Edit: Solved a weird issue.
 
Last edited:
  • Like
Reactions: -DEV-Phil-

-DEV-Phil-

Newbie
Game Developer
Jan 14, 2021
95
343
If you don't want it to be a standard menu, why are you trying to make it a standard menu ?

What you need is just a screen with image buttons, and to use the arguments passed to this screen to define what the buttons will do.

But like it would be in fact a bit more complicated that way, here's a full movie player. It take charge of the buttons and also of displaying the movie itself:
Python:
screen moviePlayer( cameras ):

    # Just to be sure it will be on top of your possible User Interface
    zorder 10

    # Store the movie actually selected.
    # Always use the first one defined as default.
    default movie = cameras[0][0]

    # Show the actually selected movie, centered
    add movie xalign 0.5 yalign 0.5

    frame:
        # Or any style you want to apply
        style "empty"

        # Position it at top right of the screen
        ypos 0   xalign 1.0

        # Display horizontally.
        #  /!\ MUST be after the style, this permit to apply style that normally
        # wouldn't apply to hbox /!\
        has hbox

        # For all the defined cameras
        for ( scene, label ) in cameras:

            # Display a button.
            vbox:
                # Firstly the button itself
                imagebutton:
                    auto "change_%s.png"
                    # that will change the selected movie.
                    action SetScreenVariable( "movie", scene )
                # Then the name for this camera.
                text "[label]"

        # Then display the "continue button"
        vbox:
            imagebutton:
                auto "advance_%s.png"
                # that will simply close the screen.
                action Return()
            text "Continue"

# Define all your movies
image movie1 = Movie( play="movies/whatever.webm" )
image movie2 = Movie( play="movies/whatever else.webm" )

label whatever:

    # Call the movie player, providing it tuples for all the movie playable.
    # Each tuple being the name of the movie and the label of the camera.
    call screen moviePlayer( [ ( "movie1", "side view" ), ( "movie2", "POV" ) ] )

    "END"
Thank you very much for the quick help and the good idea.

I have now inserted the code and defined my movies.

However, I am receiving the following error message:


Code:
File "game/screens.rpy", line 1592: expected variable or tuple pattern.
    for scene, label in cameras:
As I am afraid of breaking anything, I would like to ask for further assistance.

Best regards
Phil
 

osanaiko

Engaged Member
Modder
Jul 4, 2017
2,422
4,275
The parameter to the screen is expected to be an array of tuples, with each tuple being "movie displayable" and "text label".

If you don't know what a tuple is, check a python tutorial.


In the example from AnneO, there are two movie displayables defined: "movie1" and "movie2"

This line shows how to call the screen correctly:
Code:
call screen moviePlayer( [ ( "movie1", "side view" ), ( "movie2", "POV" ) ] )
 

-DEV-Phil-

Newbie
Game Developer
Jan 14, 2021
95
343
Hello osanaiko,



Unfortunately, your answer didn't help me either, but thank you for trying.

Perhaps I should describe it a bit better:

I inserted the code above from AnneO into my game as follows:

Code:
screen moviePlayer( cameras ):

    # Just to be sure it will be on top of your possible User Interface
    zorder 10

    # Store the movie actually selected.
    # Always use the first one defined as default.
    default movie = cameras[0][0]

    # Show the actually selected movie, centered
    add movie xalign 0.5 yalign 0.5

    frame:
        # Or any style you want to apply
        style "empty"

        # Position it at top right of the screen
        ypos 0   xalign 1.0

        # Display horizontally.
        #  /!\ MUST be after the style, this permit to apply style that normally
        # wouldn't apply to hbox /!\
        has hbox

        # For all the defined cameras
        for ( scene, label ) in cameras:

            # Display a button.
            vbox:
                # Firstly the button itself
                imagebutton:
                    auto "camera1.png"
                    # that will change the selected movie.
                    action SetScreenVariable( "movie", scene )
                # Then the name for this camera.
                text "[label]"

        # Then display the "continue button"
        vbox:
            imagebutton:
                auto "camera2.png"
                # that will simply close the screen.
                action Return()
            text "Continue"


Then I added my 2 videos in my script file as follows:

Code:
image movie1 = movie( play="movies/sarahplanefuck001view02speed01.webm" )
image movie2 = movie( play="movies/sarahplanefuck002.webm" )
and inserted the call in my script as follows:

Code:
label test:
      call screen moviePlayer( [ ( "movie1", "camera1" ), ( "movie2", "camera2" ) ] )
What is my mistake ?

Thank you for the help so far.


Best regards
Phil
 
  • Red Heart
Reactions: osanaiko

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,620
15,601
Code:
image movie1 = movie( play="movies/sarahplanefuck001view02speed01.webm" )
image movie2 = movie( play="movies/sarahplanefuck002.webm" )
Here it should be Movie( play="..." ) with the uppercase "M".


What is my mistake ?
Nowhere, it's mine ; well, strictly speaking it's not a mistake.

I tend to use short names for my variables, especially when I'm just doing some proof test. And when I copy/pasted the code, I changed them into "scene" and "label", that are more explicit for the reader, especially if he isn't much experienced.
But well, it happen that Ren'Py do not like it with those two names...

Change them by "file" and "name" and the code should (I'm cautious now) works without problems. Also don't forget to change them also in the text and action line.
Sorry for that.



Side note: edited the code to correct the issue.
 
  • Like
Reactions: osanaiko