Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | duke_meister |
edit: have reported this as a bug
ButtonGroups don’t seem to be working for me. Please have a look at this sample code. I have a GridContainer to which I add checkboxes, and an ItemList to show the output in the game window.
using Godot;
using System;
public class ItemCheckList : GridContainer
{
private ButtonGroup bg = new ButtonGroup();
private ItemList itemlist;
public override void _Ready()
{
for(int i = 0; i < 10; i++)
{
var cb = new CheckBox();
cb.SetButtonGroup(bg);
cb.Connect( "pressed", this, "OnPressed");
AddChild( cb);
}
itemlist = (ItemList)GetNode("/root/Node2D/ItemList");
}
public void OnPressed()
{
var b = bg.GetPressedButton();
if( b == null)
itemlist.AddItem("same button pressed");
else
itemlist.AddItem($"button {b.Name}");
}
}
The results I get from clicking each button from top to bottom, are:
button @@3
button @@3
button @@4
button @@6
button @@6
button @@8
button @@9
button @@9
button @@11
button @@11
edit: Why am a getting the same button name for different buttons?
Thanks.