[Solved] Is it possible to include a menu chunk into an existing menu, like this?

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
henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

[Solved] Is it possible to include a menu chunk into an existing menu, like this?

#1 Post by henvu50 »

I'm going to be using a lot of menu's, but part of the menu will always remain exactly the same. Is there a way to include a menu_chunk, so I don't have to re-type it over and over again? Like so...

Code: Select all

menu: 
    "A. Hello":
    "B. Hi":
    include("menu_chunk")

label menu_chunk:
    "Special: Static Function 1":
       $ func1()
    "Special: Static Function 2":     
       $ func2() 
Last edited by henvu50 on Tue Jul 13, 2021 7:58 pm, edited 3 times in total.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2397
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Is it possible to include a menu chunk into an existing menu, like this?

#2 Post by Ocelot »

1) Add an argument to the choice screen and pass your special functions as an argument:

Code: Select all

# menu_chunk = [("Special: Static Function 1", "func1"), ("Special: Static Function 2", "func2")]
menu (extra=menu_chunk ):
    "a":
        pass
# . . .
screen choice(items, extra=[]):
    # Usual stuff
    # After everything we add extra buttons:
    for name, function in extra:
        textbutton name action Function(function)
Or create a function to build your choice list and use renpy.display_menu to get your choices
https://www.renpy.org/doc/html/statemen ... splay_menu
< < insert Rick Cook quote here > >

henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

Re: Is it possible to include a menu chunk into an existing menu, like this?

#3 Post by henvu50 »

Ocelot wrote: Tue Jul 13, 2021 6:26 pm 1) Add an argument to the choice screen and pass your special functions as an argument:

Code: Select all

# menu_chunk = [("Special: Static Function 1", "func1"), ("Special: Static Function 2", "func2")]
menu (extra=menu_chunk ):
    "a":
        pass
# . . .
screen choice(items, extra=[]):
    # Usual stuff
    # After everything we add extra buttons:
    for name, function in extra:
        textbutton name action Function(function)
Unfortunately the special functions passed as an argument are not part of the choice index, so if you press the arrow down keys, it won't cycle to the extra menu chunk choices. They're accessible by mouse, but not by keyboard.

Adding the special function choices into the menu choices index would make them part of the index, and the special function choices could then be accessed via the arrow keys. That's why I was hoping there was a way to include the menu choices in a chunk.

Still, this should help others who don't need the special function choices to be accessed via the keyboard.

On a side note, I actually did implement your solution to some degree already and include my special functions in the index, but I haven't figured out how to avoid the list out of range error when a special function choice is selected. This error occurs because when I select my custom function, it's looking to redirect to the menu: choices, but it sees a choice is not there. Not sure how to fix that. I have to somehow cancel the redirect and instead make it use it's own function, but the special function menu choice needs SetVariable logic in its action (in order to preserve the index so arrow keys work).
Ocelot wrote: Tue Jul 13, 2021 6:26 pm Or create a function to build your choice list and use renpy.display_menu to get your choices
https://www.renpy.org/doc/html/statemen ... splay_menu
I'm going to try this solution next, perhaps it will allow me to add the special function choices, but also include them in the index, so they can be access with the arrow keys in addition to the mouse.

I have a feeling this will solve my issue.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2397
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Is it possible to include a menu chunk into an existing menu, like this?

#4 Post by Ocelot »

Works for me, all buttons are selectable from the keyboard:

Code: Select all

# screens.rpy
screen choice(items, extra=[]):
    style_prefix "choice"

    vbox:
        for i in items:
            textbutton i.caption action i.action
        for name, function in extra:
            textbutton name action Function(function)

# script.rpy
init python:
    def func1():
        renpy.jump("f1")

    def func2():
        renpy.jump("f2")

label start:
    $ menu_chunk = [("Special: Static Function 1", func1), ("Special: Static Function 2", func2)]
    menu (extra=menu_chunk ):
        "a":
            pass
    "this is a test"
    return

label f1:
    "F1"
    return
label f2:
    "F2"
    return
< < insert Rick Cook quote here > >

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Is it possible to include a menu chunk into an existing menu, like this?

#5 Post by Imperf3kt »

You could also make your own menu screen. The menu is just the choice screen with the text and arguments passed to it that it constructs buttons from and assigns actions.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

Re: Is it possible to include a menu chunk into an existing menu, like this?

#6 Post by henvu50 »

Imperf3kt wrote: Tue Jul 13, 2021 7:53 pm You could also make your own menu screen. The menu is just the choice screen with the text and arguments passed to it that it constructs buttons from and assigns actions.
I actually did do that. I got my own custom menu screen. It's working great so far.
Ocelot wrote: Tue Jul 13, 2021 7:15 pm Works for me, all buttons are selectable from the keyboard:

Code: Select all

# screens.rpy
screen choice(items, extra=[]):
    style_prefix "choice"

    vbox:
        for i in items:
            textbutton i.caption action i.action
        for name, function in extra:
            textbutton name action Function(function)

# script.rpy
init python:
    def func1():
        renpy.jump("f1")

    def func2():
        renpy.jump("f2")

label start:
    $ menu_chunk = [("Special: Static Function 1", func1), ("Special: Static Function 2", func2)]
    menu (extra=menu_chunk ):
        "a":
            pass
    "this is a test"
    return

label f1:
    "F1"
    return
label f2:
    "F2"
    return
Damn, I need to up my game. I want to get as black belt as you. Thanks again.

Now to figure out why my implementation didn't work!

Post Reply

Who is online

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