No make an menu input action when a second menu is activated

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

I made one in-game general menu that it appears or hides when the user press “Esc” button. Now I have created a second menu (Option menu) that it is called from general menu, the problem is that if the user press “Esc” button when the option menu is open the general menu catch it and closes, but I only want the options menu to take the inputs until it closes.

General menu inputs code:

func _input(event):
	if event.is_action_pressed("ui_cancel"):
		if get_node("GameMenu").is_visible_in_tree():
			get_node("GameMenu").hide()
		else:
			get_node("GameMenu").show()

func _on_Options_pressed():
	# Intance Options Menu in the Scene
	var optionsMenu = load("res://OptionsMenu.tscn").instance()
	add_child(optionsMenu)
	get_node("OptionsMenu").connect("CloseOptionsMenu", self, "CloseOptionsMenu")

func CloseOptionsMenu():
	get_node("OptionsMenu").queue_free()

Option menu inputs code:

func _input(event):
	if event.is_action_pressed("ui_cancel"):
		emit_signal("CloseOptionsMenu")
:bust_in_silhouette: Reply From: BlockOG

You can make a singleton script called Global and then put this code in that script:

var options_menu_open = false

And in the general menu inputs script:

func _input(event):
    if event.is_action_pressed("ui_cancel") and !Global.options_menu_open:
        if get_node("ui_cancel").is_visible_in_tree():
            get_node("ui_cancel").hide()
        else:
            get_node("ui_cancel").show()

func _on_Options_pressed():
    # Intance Options Menu in the Scene
    Global.options_menu_open = true
    var optionsMenu = load("res://OptionsMenu.tscn").instance()
    add_child(optionsMenu)
    get_node("OptionsMenu").connect("CloseOptionsMenu", self, "CloseOptionsMenu")

func CloseOptionsMenu():
    Global.options_menu_open = false
    get_node("OptionsMenu").queue_free()

Options menu inputs script(there’s nothing different):

func _input(event):
    if event.is_action_pressed("ui_cancel"):
        emit_signal("CloseOptionsMenu")

Your solution don’t work because the program call first this function:

func CloseOptionsMenu():
Global.options_menu_open = false
get_node("OptionsMenu").queue_free()

Instead of the general menu _input() function, so the input pass to general menu.

But you give me an good idea to solve it. I and a variable to the signal to say if the option menu closed via button or input key AND IT WORKS.
Thanks for your help

—FINAL CODE—
General menu script:

func _input(event):
if event.is_action_pressed("ui_cancel") and !Global.secondary_menu_close_with_Input:
	if get_node("GameMenu").is_visible_in_tree():
		get_node("GameMenu").hide()
	else:
		get_node("GameMenu").show()
Global.secondary_menu_close_with_Input = false

func _on_Options_pressed():
	# Intance Options Menu in the Scene
	var optionsMenu = load("res://OptionsMenu.tscn").instance()
	add_child(optionsMenu)
	get_node("OptionsMenu").connect("CloseOptionsMenu", self, "CloseOptionsMenu")

func CloseOptionsMenu(closeWithInput : bool):
	if closeWithInput:
		Global.secondary_menu_close_with_Input = true
	else:
		Global.secondary_menu_close_with_Input = false
	get_node("OptionsMenu").queue_free()

Options menu script:

func _input(event):
	if event.is_action_pressed("ui_cancel"):
		emit_signal("CloseOptionsMenu", true)

func _on_Close_pressed():
	emit_signal("CloseOptionsMenu", false)

david_Amlag | 2020-12-09 21:09