Game Development Community

Selecting Radio Buttons

by David Taylor · in Torque Game Builder · 09/07/2006 (10:11 pm) · 3 replies

I've got several radio buttons in one of my guis. If I click on one, it deselects the others. That's fine, except I want to be able to do that IN GROUPS.

What I mean by that, is I want to be able to have groups of five radio buttons in the same gui. Within each group, selecting a radio button deselects the other four. But it doesn't affect any of the other groups.

How can I do this? I've tried adding a new guictrl within the gui, as well as adding a t2dSceneWindow. What am I missing?

#1
09/08/2006 (7:34 am)
Radio buttons can be a bit tricky. If you have experience from any other program, you'll quickly discover that Torque radio buttons are pretty primitive.

To establish groups of radio buttons... Give each group a unique groupNum in the GuiRadioCtrl. For example, groupNum = "1";, set to five radio buttons would establish them as a group. This group should be the only radio buttons with this groupNum in that GUI.

Now comes the tricky part. There is no way to script via groupNum. You have to script each radio button explicitly. You have to set the default values for every button (you can't set one in a group to true and assume that the rest will be false - this isn't always the case, but needs to be done or you'll get in trouble). You also have to create functions for every radio button like this:
function RadioButton1A::onAction(%this)
{
if ( %this.getValue() == true )
{
... put script here ...
}
}

While you end up coding something you'd think the engine would handle, the advantages of using radio buttons outweighs their primitive natures.
#2
09/08/2006 (9:29 am)
This is a fair observation--radio button implementation is (still) very primitive, and not what we would expect. Don points out the best way to mimic true radio button behaviour.

Unfortunately this has been a very low priority item for Torque, and hasn't made it up to re-implementation.
#3
09/12/2006 (1:38 am)
Thanks, Don. I just tried your method, and it worked a dream. Thanks again. :)