Menu Option Highlight Issue

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
User avatar
Westeford
Regular
Posts: 151
Joined: Mon Jun 19, 2017 4:43 pm
Completed: 12 Hours to Die
Projects: Project Premonition
itch: westeford
Location: United States
Contact:

Menu Option Highlight Issue

#1 Post by Westeford »

So I have some screens working in my game. When I click on a menu item, it highlights to show it's selected. But I found that the menu items stay highlighted even after leaving the menu.

Here's a video to show what I mean.
https://youtu.be/PlT-owi2OYk

Here's the code for the move menu (The menu used in the video.)

Code: Select all

screen move_menu():
    tag act0
    default selected_item = None
    default selected_location = None
    add "ui/menu_list.png" at fastFade:
        pos (1089, 354)
    fixed at fastFade:
        xysize (416, 426)
        pos (1101, 366)
        vpgrid:#vbox:
            cols 1
            spacing -4
            draggable True
            mousewheel True
            scrollbars "vertical"
            xpos 0 #147
            ypos 0 #57
            side_xalign 0.0
            for location_item in location_list:
                textbutton location_item.name xysize (401, 50):
                    bottom_margin 10
                    right_margin 5
                    left_padding 10 #25
                    text_size 25
                    text_color "fff"
                    background "#222"
                    hover_background "#f00"
                    selected_background "#960000"
                    action (SetVariable("selected_location", location_item.name)), (SetScreenVariable("selected_item", location_item))

    fixed at fastFade:
        xysize (391,230) #(369, 208)
        xpos 1530 #1538
        ypos 355 #366
        if selected_item:
            add "inv_bg":
                yalign 0.5 xalign 0.5
            add selected_item.pic:
                yalign 0.5 xalign 0.5

    fixed at fastFade:
        # xysize (273, 175)
        xpos 1530
        ypos 587
        if selected_item:
            frame:
                textbutton "Go" action Hide("move_menu"), Hide("action_menu"), Jump("location_manager")
        else:
            null
        # text "Go"

    imagebutton pos (1240, 823) at fastFade:
        idle "ui/travel_button.png" hover "ui/travel_button.png" action Hide("move_menu")
I want the option to stop being highlighted after leaving the menu.
I appreciate any suggestions.

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

Re: Menu Option Highlight Issue

#2 Post by Ocelot »

First, you should understand, how button deterrmines if it is selected or not. First of all it looks for selected property. If provided, button will be selected if it evaluates to True and deselected otherwise. If selected property is not provided, it looks at the actions to determine if button is selected. I do not remember which action is selected if list of actions is provided, but for Set*Variable family of action button is considered selected if variable is already assigned desired value. In your case, for example, it will be selected if variable selected_location equals to location_item.name

TL;DR: reset your variable to None each time the screen is shown.
< < insert Rick Cook quote here > >

User avatar
Westeford
Regular
Posts: 151
Joined: Mon Jun 19, 2017 4:43 pm
Completed: 12 Hours to Die
Projects: Project Premonition
itch: westeford
Location: United States
Contact:

Re: Menu Option Highlight Issue

#3 Post by Westeford »

Ocelot wrote: Wed Mar 24, 2021 12:49 pm TL;DR: reset your variable to None each time the screen is shown.
Isn't that what the following does?

Code: Select all

    default selected_item = None
    default selected_location = None
Or is there another screen function I'm not finding?

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

Re: Menu Option Highlight Issue

#4 Post by Ocelot »

I do not remember in which cases it reset variables, but at least this SetVariable("selected_location", location_item.name) sets global variable (or, rather, store variable) and not screen variable, so it is not affected by default statement.
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: Dark79, Ikaros_OwO, Zapor