Multiple Menus Not Working

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
lindsay-jb
Regular
Posts: 68
Joined: Tue Aug 25, 2020 1:05 am
Contact:

Multiple Menus Not Working

#1 Post by lindsay-jb »

Hey! So in addition to the regular position of the menu, I have two others I use occasionally: at the middle and at the bottom. But I'm having some problems. When the bottom menu is activated, everything looks good EXCEPT that the menu choices are shown again at the top left of the screen. They're not in the button, it's just the text. Then, when those menus are deactivated, the regular menu buttons don't show up at all, including the text. However, if I just have the bottom or the middle menus coded and setup in the screens section, everything works fine. It's when I have both of them that it starts being weird. I'm sure I did something wrong. I just made this by looking around the forums and tweaking stuff myself, so it's probably a simple fix lol. I just can't pinpoint the problem. Anyway, help would be appreciated. Here's the code.

Code: Select all

screen choice(items):
    if middle:
        window:
            style "menu_window"
            xalign 0.0
            xpos 25
            ypos 720
            yanchor 0.0

            style_prefix "choice"
            vbox:
                style "menu"
                spacing 2
                for i in items:
                    textbutton i.caption:
                        action i.action
                        text_align (0.05, 0.5)

    if bottom:
        window:
            style "menu_window"
            xalign 0.0
            xpos 25
            ypos 1000
            yanchor 0.0

            style_prefix "choice"
            vbox:
                style "menu"
                spacing 2
                for i in items:
                    textbutton i.caption:
                        action i.action
                        text_align (0.05, 0.5)

    if (timeout_label is not None) and persistent.timed_choices:

        bar:
            xalign 0.5
            ypos 100
            xsize 740
            value AnimatedValue(old_value=0.0, value=1.0, range=1.0, delay=timeout)

        timer timeout action Jump(timeout_label)

    else:
        style_prefix "choice"
        vbox:
            for i in items:
                textbutton i.caption:
                    action i.action
                    text_align (0.05, 0.5)

lindsay-jb
Regular
Posts: 68
Joined: Tue Aug 25, 2020 1:05 am
Contact:

Re: Multiple Menus Not Working

#2 Post by lindsay-jb »

I ended up doing this:

Code: Select all

screen choice(items):
    if middle:
        window:
            xalign 0.0
            xpos 25
            ypos 720
            yanchor 0.0

            style_prefix "choice"
            vbox:
                style "menu"
                spacing 2
                for i in items:
                    textbutton i.caption:
                        action i.action
                        text_align (0.05, 0.5)

    if bottom:
        window:
            xalign 0.0
            xpos 25
            ypos 1000
            yanchor 0.0

            style_prefix "choice"
            vbox:
                style "menu"
                spacing 2
                for i in items:
                    textbutton i.caption:
                        action i.action
                        text_align (0.05, 0.5)

    if regular:
        window:
            xalign 0.0
            xpos 0.0
            ypos 900
            yanchor 0.0

            style_prefix "choice"
            vbox:
                style "menu"
                spacing 2
                for i in items:
                    textbutton i.caption:
                        action i.action
                        text_align (0.05, 0.5)
        style_prefix "choice"

    if (timeout_label is not None) and persistent.timed_choices:

        bar:
            xalign 0.5
            ypos 100
            xsize 740
            value AnimatedValue(old_value=0.0, value=1.0, range=1.0, delay=timeout)

        timer timeout action Jump(timeout_label)
Getting rid of the else argument seemed to fix it so i guess it's all good.

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Multiple Menus Not Working

#3 Post by zmook »

lindsay-jb wrote: Wed Jun 09, 2021 10:32 pm Hey! So in addition to the regular position of the menu, I have two others I use occasionally: at the middle and at the bottom. But I'm having some problems. When the bottom menu is activated, everything looks good EXCEPT that the menu choices are shown again at the top left of the screen. They're not in the button, it's just the text.
That's what your else clause said to do: put a vbox with textbuttons in it on the screen.

I'm wondering if you think your "if" cases are all mutually exclusive, because they're not coded that way. if it's possible for "middle" and "bottom" to both be True, then renpy will try to display both blocks. If you want to guarantee that renpy will only show one or the other, the second and subsequent ones should be `elif`.

It also might be instructive to look at the content of your screen, stripped of all the style and layout information:

Code: Select all

screen choice(items):
    if middle:
        window:
            vbox:
                for i in items:
                    textbutton i.caption

    # this is the start of an entirely new if/elif/else statement, independent of anything above it
    if bottom:
        window:
            vbox:
                for i in items:
                    textbutton i.caption

    # this is the start of an entirely new if/elif/else statement, independent of anything above it
    if (timeout_label is not None) and persistent.timed_choices:
        bar value AnimatedValue(old_value=0.0, value=1.0, range=1.0, delay=timeout)
        timer timeout action Jump(timeout_label)
    else:
        vbox:
            for i in items:
                textbutton i.caption
The third if/else statement in particular doesn't seem right, but I don't understand what you intend, really.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

lindsay-jb
Regular
Posts: 68
Joined: Tue Aug 25, 2020 1:05 am
Contact:

Re: Multiple Menus Not Working

#4 Post by lindsay-jb »

Thank you! I figured my code was sort of messy... I'm a writer/musician who had an idea for a VN and decided to learn to program so my codes are usually weird mixes of different tutorials/answered questions I find lol. I didn't know about the enif, that's super helpful! I'll use your suggestions to clean up the coding.

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot]