Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | mimmo970 |
I am trying to generate a Container that displays a bunch of items as Check Buttons, so that those that are selected get their text appended to a list. Here is my code:
var items = ["Item 1", "Item 2", "Item 3"]
var selected_items = []
func _ready():
var vbox = VBoxContainer.new()
add_child($vbox)
for item in items:
var check_button = CheckButton.new()
check_button.text = item
check_button.connect("toggled", self, "_on_item_toggled", [item])
$vbox.add_child(check_button)
func _on_item_toggled(item, value):
if value:
selected_items.append(item)
else:
selected_items.erase(item)
print("Selected items: ", selected_items)
However what gets printed is
Selected items: [True, True, True]
rather than the actual items.
Thanks for any help
mimmo