Game Development Community

Fun with actionmaps.

by Jaybill · in Torque Game Builder · 02/03/2006 (8:26 pm) · 5 replies

Hi all.

Okay, two related questions:

1) Seemingly when I assign the same function to two keys the first key no longer works. In the code below...

moveWorldMap.bind(keyboard, left, "mapLevelDown");
moveWorldMap.bind(keyboard, right, "mapLevelUp");
moveWorldMap.bind(keyboard, down, "mapLevelDown");
moveWorldMap.bind(keyboard, up, "mapLevelUp");
moveWorldMap.bind(keyboard, space, "mapChooseLevel");

..."up" and "down" work but "left" and "right" do not. If I reverse the order the opposite happens. (Right and left work, up and down do not.) The push is not included because I do that elsewhere based on what is happning.

2) Is there a list of key aliases (up, down, esc, tilda, etc) somewhere? I looked hard and could not find one.

#1
02/06/2006 (6:03 pm)
So...no idea? Can I provide any additional information?
#2
02/06/2006 (6:11 pm)
www.garagegames.com/mg/forums/result.thread.php?qt=2272

If you can't see the post, here's the part that matters:

Quote:Ok... it's a stupid simple change that took me less than a 5 minutes to find, fix, and test. In ActionMap::processBind just comment this sucker out:

// We have decided to only allow one bind per console function, so
   // remove any existing nodes that are bound to the given function:
   /*
   if ( pFnName[0] )
   {
      U32 devMapIndex, nodeIndex;
      while ( findBoundNode( pFnName, devMapIndex, nodeIndex ) )
      {
         dFree( mDeviceMaps[devMapIndex]->nodeMap[nodeIndex].makeConsoleCommand );
         dFree( mDeviceMaps[devMapIndex]->nodeMap[nodeIndex].breakConsoleCommand );
         mDeviceMaps[devMapIndex]->nodeMap.erase( nodeIndex );
      }
   }
  */


Wow... that was easy. Now the harder part... fixing the control mapping GUI. In OptionsDlg.cs within the OptRemapInputCtrl::onInputEvent function make the following change:

%cmd  = $RemapCmd[%this.index];
   %name = $RemapName[%this.index];

   // START ADDED CODE!

   // First remove all other bindings of this command... one
   // binding per command is all that this gui is *designed* for.
   while ( true ) 
   {
      %oldBind = moveMap.getBinding( %cmd );

      if ( %oldBind $= "" )
         break;

      moveMap.unbind( getWord( %oldBind, 0 ), getWord( %oldBind, 1 ) );
   }

   // END ADDED CODE!

   // First check to see if the given action is already mapped:
	%prevMap = moveMap.getCommand( %device, %action );
   if ( %prevMap !$= %cmd )
   {


I guess it wasn't that hard, but it took me longer to come up with an adequate solution. The problem is that to support multiple bindings per command the options dialog needs to be redesigned in a way so that the user can see and change any of the X bindings on each command.

It would be super cool that after I contributed this that someone else would come in and do a redesign of the control mapping dialog to support lets say 3 binds per-command.
#3
02/12/2006 (6:34 pm)
D'oh.

There is another, far, far simpler and more obvious solution that just occured to me. Not that the suggested approach wouldn't work, but my way can be done without changing the engine code. If two keys are to be bound to the same function, make one function for each binding and have those functions call the *actual* function.


Basic example with gratuitous Harvey Birdman joke:

new ActionMap(moveMap); 

function doItWithKeyOne(%val){
   doSomething(%val);
}

function doItWithKeyTwo(%val){
   doSomething(%val);
}

function doSomething(%val){
   ThatThingISentYou.get();
}

moveMap.bind(keyboard, right, "doItWithKeyOne","Move Right");
moveMap.bind(keyboard, up, "doItWithKeyTwo","Move Up");
#4
02/13/2006 (5:02 am)
The way i'd do it would be to make another keymap for alternate keys. ie..

new ActionMap(moveMap);
moveMap.bind(keyboard, left, "moveLeft");
moveMap.bind(keyboard, right, "moveRight");
moveMap.bind(keyboard, up, "moveUp");
moveMap.bind(keyboard, down, "moveDown");
moveMap.push();

new ActionMap(altMoveMap);
altMoveMap.bind(keyboard, a, "moveLeft");
altMoveMap.bind(keyboard, d, "moveRight");
altMoveMap.bind(keyboard, w, "moveUp");
altMoveMap.bind(keyboard, s, "moveDown");
altMoveMap.push();
#5
02/13/2006 (6:26 pm)
@david - Thanks for for the response. My problem was actually a litte different in that I was trying to do the same thing with two different keys in the same circumstance. On my "world map" the player can really only move to the next map dot or the previous map dot. While "left" and "right" seem like the obvious way to move back and forth between them, there are some that look like they might be "up" or "down" from the current location. It felt really counterintuitive despite being "right". So I wanted "up" and "left" to do the same thing (move backwards) as well as "down" and "right" to move forwards.