0 votes

I'm trying to get a function that grabs the currently viewed menu, and sends a "back/return to previous menu" output using Button nodes.

For the most part, the code works as expected, except it keeps the previous entries when used. For example, if I have a last button named "quit" in a first menu, and "back" in a secondary one, it would output "quit" on the first one but then:

quit
back

How would I go about clearing out prior entries in the list?

var back setget _set_back , _get_back

func _input(event):
    if event.is_action_pressed('ui_cancel'):
        if _get_back() != null:
            print(_get_back().name)

func _grab_menu():
    var menu = []
    for i in get_children():
        if i.get_class() == 'Button' && i.visible:
            menu.append(i)
    _set_back(menu.back())
    menu.clear()

func _set_back(menu):
    back = menu

func _get_back():
    return back
Godot version 3.2.3
in Engine by (29 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.