Can't move selection in options menu

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ertain

I’m trying to make an options screen that’s maneuverable by pressing the arrow keys (or by the directional pad on a controller).

Options screen

I have tried putting in code to allow for this form of navigation. When the user presses down a few times, the “Credits” option is the only thing highlighted, even though the player should be able to control which option is highlighted. I don’t know why it won’t highlight another option when the player presses up or down.

The following is the code for the options screen:

extends Control

# Which option is selected?
var option_number: int = 0
var shadow_color: String = "2dea12"

# Nodes to reference
onready var x_sensitivity: Label = $"VBoxContainer/HBoxContainer/X-sensitivity"
onready var y_sensitivity: Label = $"VBoxContainer/HBoxContainer2/Y-sensitivity"
onready var test_play: Label = $VBoxContainer/Test_play
onready var credits: Label = $VBoxContainer/Credits

# Collect all the options into an array for handy reference.
var list_of_options: Array = []

func _ready():
    list_of_options = [
    x_sensitivity, y_sensitivity, test_play, credits
]

# Depending upon whether the player presses up or down on the directional pad, increment or decrement the "option_number" variable.
func _input(event):
    if event.is_action_pressed("ui_down"):
        option_number = clamp( option_number + 1.0, 0.0, list_of_options.size() - 1 )
    if event.is_action_pressed("ui_up"):
        option_number = clamp( option_number - 1.0, 0.0, list_of_options.size() - 1 )

func _process(change_in_frame):
    if option_number > list_of_options.size() - 1:
        return
    elif option_number < 0:
        return
    for option in [0,1,2,3]:
        if option == option_number:
            # Make the option letters look highlighted.
            list_of_options[option_number].add_color_override( "font_color_shadow", Color(shadow_color) )
            list_of_options[option_number].add_constant_override("shadow_as_outline", 2)
        else:
            # Make the option letters look plain.
            list_of_options[option_number].add_color_override("font_color_shadow", ColorN("black") )
            list_of_options[option_number].add_constant_override("shadow_as_outline", 0)

Didnt really dove deep into your code, more of a side note, the Control scenes have the option to set which Control node will be at where when you press the directions

rustyStriker | 2019-12-10 20:56

So there’s an option in the editor to keep track of whichControl widgets after selected when the project is run?

Ertain | 2019-12-11 00:39

Indeed, it’s the focus_neighbour_... settings on the node

rustyStriker | 2019-12-11 10:41

Easy to move selection menu in options menu with the help of null value reference.and input/ selection from keyboard and mouse.

assignmentservice | 2019-12-12 14:18

:bust_in_silhouette: Reply From: Ertain

rustyStriker told me about the focus_neightbour_[...] properties in the editor. I was able to assign the focus_neighbour_top and focus_neighbour_bottom properties to the nodes I want highlighted. KBraven in the Godot Discord channel clued me into setting the focus_modes of the Labels (I set them to “All”). So now I can use the “ui_up” and “ui_down” keys to select the options.