Closing a custom screen chooses a menu item.

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
Swinwappy
Newbie
Posts: 14
Joined: Mon Jun 01, 2020 3:52 am
Contact:

Closing a custom screen chooses a menu item.

#1 Post by Swinwappy »

Hey guys, I have a phone UI in my game. Whenever I open this UI in a zone with a menu, the last item in the menu is selected.

Does anyone have any idea why this might be happening?

Here's a video of the bug in action.
https://youtu.be/hz1tgVsYOB0

This is the MC's bedroom, where menus are present.

Code: Select all

 label bedroom:
        call screensrefresh

        if clock.time_of_day in ["10PM", "11PM", "12AM", "1AM", "2AM", "3AM"]:
            scene bedroomnighttime with fade
        else:
            scene bedroomday with fade
        menu:
            "Work out":
                "You work out for an hour."
                $ clock.advance(1)
                jump bedroom

            "Study":
                "You study for an hour."
                $ clock.advance(1)
                jump bedroom

            "nada":
                "de nada" #exiting the hud will always choose the last menu item
        jump bedroom
    return
This is the button to close the phone:

Code: Select all

screen hud():
    hbox xalign 0.5 yalign 0.945:
        #phone home button
        imagebutton:
            idle "homebutton.png"
            hover "homebuttonhover.png"
            action Call ("phoneexit")
This is the "function" that closes the phone screen.

Code: Select all

label phoneexit:
    hide screen hud
    show screen hud
    hide screen phonebuttons
    hide screen phoneprofiles
    hide screen contactnames
    hide phonehome
    hide phoneprofiles
    hide phonemain
    hide screen phoneprofilescreen
    hide screen contactnames
    hide phonemap
    hide screen map
    pause .1
    return

Swinwappy
Newbie
Posts: 14
Joined: Mon Jun 01, 2020 3:52 am
Contact:

Re: Closing a custom screen chooses a menu item.

#2 Post by Swinwappy »

Ok, I think it has something to do with the returning. When I replace "Return" with "Jump Bedroom" on the function that closes the phone screen, it seems to work fine.

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

Re: Closing a custom screen chooses a menu item.

#3 Post by Ocelot »

Calling a label terminates current statement (in your case a menu statement) by default. I am pretty surprised it actually chose anything instead of skipping menu entirely. Baiscally, don't call stuff if you are not done with stuff on the screen.
< < insert Rick Cook quote here > >

Swinwappy
Newbie
Posts: 14
Joined: Mon Jun 01, 2020 3:52 am
Contact:

Re: Closing a custom screen chooses a menu item.

#4 Post by Swinwappy »

Ocelot wrote: Thu Jan 04, 2024 11:04 am Calling a label terminates current statement (in your case a menu statement) by default. I am pretty surprised it actually chose anything instead of skipping menu entirely. Baiscally, don't call stuff if you are not done with stuff on the screen.
Thanks for the response. Do you have any idea how I might close this menu when the player opens there phone? Is there a better way of doing this?

Cheers.

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

Re: Closing a custom screen chooses a menu item.

#5 Post by Ocelot »

Yes, just hide the screen and do not call any labels if you want for it to work properly in menus. Alternatively, disable ability to use phone in menus.
To handle ungodly amount of hiding you do, either make them be used in some kind of root screen, or hide them in Python function you can invoke.
You can also try Call ("phoneexit", from_current=True) but this can lead to problems in other places.
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: No registered users