Clearing out values which were set using setget on a Button node

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

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