actionMap.getBinding() possible bug?
by Paul /*ilys*/ Symeou · in Torque Game Engine · 01/16/2010 (2:04 pm) · 1 replies
All of the Torque engines allow you to set multiple binds to the same command. However, the majority of the scripting will only grab the first instance of the bind.
In actionMap.cs (which you can find in either "common/client", "common/clientScripts" or "cores/cripts/client" for the 3D game engines, don't know if T2D has the same feature) the copyBind() and blockBind() functions grab the binding and checks the first two fields. If, for instance, you have move left bound to "a" and "left arrow", you will only copy the "a" bind and not the "left arrow" bind.
The buildFullMapString() function in optionsDlg.cs works around this by using a count hack assuming actionMap.getBinding() will always return two fields for each bind. While it may work to display the binds, it is a pretty silly way to do it.
For me, the quickest way to fix this is to fix the actionMap.getBinding() function in code.
In "sim/actionMap.cc", ActionMap::getBinding(), there is a line that looks like:
With that line changed to use n instead of t, the scripting can now be changed to suit.
Using TGE 1.5.2 as an example:
common/client/actionMap.cs
starter.fps/client/scripts/optionsDlg.cs
So, with those changes, at any time you use actionMap.copyBind(otherMap, command); it will now copy all the binds you have set for that command instead of just the first one.
Again, not sure if this is really a bug, but it annoyed me for a few minutes trying to figure out why my binds were not copying.
In actionMap.cs (which you can find in either "common/client", "common/clientScripts" or "cores/cripts/client" for the 3D game engines, don't know if T2D has the same feature) the copyBind() and blockBind() functions grab the binding and checks the first two fields. If, for instance, you have move left bound to "a" and "left arrow", you will only copy the "a" bind and not the "left arrow" bind.
The buildFullMapString() function in optionsDlg.cs works around this by using a count hack assuming actionMap.getBinding() will always return two fields for each bind. While it may work to display the binds, it is a pretty silly way to do it.
For me, the quickest way to fix this is to fix the actionMap.getBinding() function in code.
In "sim/actionMap.cc", ActionMap::getBinding(), there is a line that looks like:
dStrcat( returnString, "t" );That line adds a new field if there is more than one bind available to the command. What it really should be doing is adding a new record (n) so you can differentiate the binds more easily.
With that line changed to use n instead of t, the scripting can now be changed to suit.
Using TGE 1.5.2 as an example:
common/client/actionMap.cs
...
function ActionMap::copyBind( %this, %otherMap, %command )
{
if ( !isObject( %otherMap ) )
{
error( "ActionMap::copyBind - "" @ %otherMap @ "" is not an object!" );
return;
}
%fullMapString = %otherMap.getBinding( %command );
if ( %fullMapString !$= "" )
{
%mapCount = getRecordCount( %fullMapString );
for ( %i = 0; %i < %mapCount; %i++ )
{
%bind = getRecord( %fullMapString, %i );
%device = getField( %bind, 0 );
%action = getField( %bind, 1 );
%flags = %otherMap.isInverted( %device, %action ) ? "SDI" : "SD";
%deadZone = %otherMap.getDeadZone( %device, %action );
%scale = %otherMap.getScale( %device, %action );
%this.bind( %device, %action, %flags, %deadZone, %scale, %command );
}
}
}
//------------------------------------------------------------------------------
function ActionMap::blockBind( %this, %otherMap, %command )
{
if ( !isObject( %otherMap ) )
{
error( "ActionMap::blockBind - "" @ %otherMap @ "" is not an object!" );
return;
}
%fullMapString = %otherMap.getBinding( %command );
if ( %fullMapString !$= "" )
{
%mapCount = getRecordCount( %fullMapString );
for ( %i = 0; %i < %mapCount; %i++ )
{
%bind = getRecord( %fullMapString, %i );
%this.bind( getField( %bind, 0 ), getField( %bind, 1 ), "" );
}
}
}starter.fps/client/scripts/optionsDlg.cs
...
function buildFullMapString( %index )
{
%name = $RemapName[%index];
%cmd = $RemapCmd[%index];
%fullMapString = %actionMap.getBinding( %cmd );
if ( %fullMapString $= "" )
return %name TAB "";
%mapString = "";
%count = getRecordCount( %fullMapString );
for ( %i = 0; %i < %count; %i++ )
{
if ( %mapString !$= "" )
%mapString = %mapString @ ", ";
%temp = getRecord( %fullMapString, %i );
%device = getField( %temp, 0 );
%object = getField( %temp, 1 );
%mapString = %mapString @ getMapDisplayName( %device, %object );
}
return %name TAB %mapString;
}
...So, with those changes, at any time you use actionMap.copyBind(otherMap, command); it will now copy all the binds you have set for that command instead of just the first one.
Again, not sure if this is really a bug, but it annoyed me for a few minutes trying to figure out why my binds were not copying.
Torque Owner CSMP
MP Studios