Game Development Community

Bug in GuiButtonBaseCtrl

by Josh Moore · in Torque Game Engine Advanced · 06/12/2006 (2:31 pm) · 1 replies

I found a bug in the GuiButtonBaseCtrl that makes toggle buttons that use console commands call the script function twice. In my case, I have the console command toggling a rendering mode for a GUI, so when I would toggle the checkbox, the rendering mode would just get turned on and then right off again.

The onAction method calls Con::evaluate to run the script function:
void GuiButtonBaseCtrl::onAction()
{
    if(!mActive)
        return;

    if(mButtonType == ButtonTypeCheck)
    {
        mStateOn = mStateOn ? false : true;

        // Update the console variable:
        if ( mConsoleVariable[0] )
            Con::setBoolVariable( mConsoleVariable, mStateOn );
        // Execute the console command (if any)
        [b]if( mConsoleCommand[0] )
           Con::evaluate( mConsoleCommand, false );[/b]

	}
	else if(mButtonType == ButtonTypeRadio)
    {
        mStateOn = true;
        messageSiblings(mRadioGroup);
    }		
    setUpdate();
    Parent::onAction();
}

However, the GuiControl::onAction method also runs the console command, making the button base's call redundant:
void GuiControl::onAction()
{
   if (! mActive)
      return;

   //execute the console command
   if (mConsoleCommand[0])
   {
   	  char buf[16];
      dSprintf(buf, sizeof(buf), "%d", getId());
      Con::setVariable("$ThisControl", buf);
      Con::evaluate(mConsoleCommand, false);
   }
   else
      Con::executef(this, 1, "onAction");
}
Also, I'm wondering why the heck the onAction callback won't be called if you have a console command. Seems like bad limitation to me.


This is from TSE HEAD as from the last 2 days. I'm guessing this is also a TGE 1.4(and perhaps T2D) bug, but I haven't checked.