Game Development Community

Switch Button tipes calls its commad twice fix

by Andrea Barolo · in Torque Game Engine · 01/25/2008 (10:08 am) · 0 replies

Hello everyone.

I think I discovered a bug into button code , in particular into the GuiButtonBaseCtrl class!!

Try this: create a normal button (graphics buttons are affected too) and use the toggleButton Type

then try write this code wherever you whant:
function switchButton(){

$pass = $pass+1;
echo("Switch pressed !!!");
echo($pass);

}

Then add this to the command prop. of the button.

You ll' see this
on the consolle when you press the switch:
Switch pressed !!!
1
Switch pressed !!!
2

!!!!!!!!!!!!!!!!!

According to me there is a unneeded execute command call on GuiButtonBaseCtrl.

So go to GuiButtonBaseCtrl.cc and search for void GuiButtonBaseCtrl::onAction() method !!

Comment out this code :
// Execute the console command (if any)
        if( mConsoleCommand[0] )
        {
            char buf[16];
            dSprintf(buf, sizeof(buf), "%d", getId());
            Con::setVariable("$ThisControl", buf);
            Con::evaluate( mConsoleCommand, false );
        }

The bug evaporates !!!