0 votes

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.

in Engine by (722 points)
edited by

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 Frequently asked questions and 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 [email protected] with your username.