More key binding problems
by Philip Mansfield · in Torque Game Builder · 06/07/2006 (8:20 am) · 6 replies
I'm having a little bit of trouble getting a function mapped to a keyboard command, and I just can't see what I'm doing wrong. Here's the code:
On a related note, the function doesn't appear in the list if I go into Edit -> Preferences in the Level Builder. The movement functions are present though.
function setupKeybinds()
{
// if the action maps exist, delete them
if( isObject(gameActionMap) )
gameActionMap.delete();
// create a new action map for the game
new ActionMap(gameActionMap);
gameActionMap.bind(keyboard, "left", "p1MoveLeft");
gameActionMap.bind(keyboard, "right", "p1MoveRight");
gameActionMap.bind(keyboard, "up", "p1MoveUp");
gameActionMap.bind(keyboard, "down", "p1MoveDown");
gameActionMap.bindCmd(keyboard, "g", "p1ThrowBomb();","");
}
function p1ThrowBomb()
{
echo("throw");
// player wants to throw a bomb
if ($p1.bomb $= "B" )
{
$p1.bomb = "NB";
$p1.carriedBombId.setCollisionSuppress(true);
$p1.carriedBombId.dismount();
}
}The directional keys all work fine, it's binding the 'p1ThrowBomb' function that I'm having trouble with. Regardless of what I try ( bind vs bindCmd and various different key assignments) it just won't work. If I run the function from the console it works, so I know the code in the p1ThrowBomb function is OK. To say it's driving me batty is a slight understatement.On a related note, the function doesn't appear in the list if I go into Edit -> Preferences in the Level Builder. The movement functions are present though.
#2
I have also tried popping and then pushing the action map from the console once the game is in progress, and it makes no difference.
06/07/2006 (8:48 am)
The action map gets pushed when I start the game (in a different function). If it were something that simple, I probably would have spotted it when none of the keybindings in gameActionMap were working :)I have also tried popping and then pushing the action map from the console once the game is in progress, and it makes no difference.
#3
06/07/2006 (8:54 am)
Is it possible that the "g" command gets overridden by another action map that binds a command to "g"?
#4
I think the binding is just being completely ignored, hence the fact it's missing from the keybindings Options window.
06/07/2006 (9:02 am)
As I said, I've tried various different key bindings. Left control, space, g, u and so-on. It's unlikely that all of these are assigned elsewhere. I'm running with the editors enabled, but I don't think that's going to be the problem. In addition to the editor/global action maps, I have another for navigating menus, and that uses the arrow keys with Enter to select. That action map is popped as my game starts, and then the gameActionMap is pushed.I think the binding is just being completely ignored, hence the fact it's missing from the keybindings Options window.
#5
Have you tried adding that line just to see if it works or not?
I had to do that for mine and I had the same thing where left/right were working but not my other commands. In looking at the source there is a huge difference in the way bind and bindCmd are treated. Among other things, binds can only have one associated function so if they are already mapped (and many are in the common files) the new one just takes over.
06/07/2006 (9:10 am)
Are you getting any errors in your console.log?Have you tried adding that line just to see if it works or not?
I had to do that for mine and I had the same thing where left/right were working but not my other commands. In looking at the source there is a huge difference in the way bind and bindCmd are treated. Among other things, binds can only have one associated function so if they are already mapped (and many are in the common files) the new one just takes over.
#6
I changed things around as follows:
I found that in \common\preferences there is a file called bind.cs. I haven't been through the source to see where this gets created, but it overwrites any keybindings you try and set through script. After deleting it a few times, my new keybindings finally took.
I think what may have happened is that I have a tendancy to bring down the console and type 'quit();' rather than exit gracefully. So maybe that file wasn't getting updated properly when the game shut down.
Still, now I know I can delete it into submission, I'll just add it to the cleandso.bat file :)
06/07/2006 (9:49 am)
I have finally gotten to the bottom of it.I changed things around as follows:
function setupKeybinds()
{
// if the action maps exist, delete them
if( isObject(gameActionMap) )
gameActionMap.delete();
// create a new action map for the game
new ActionMap(gameActionMap);
gameActionMap.bindCmd(keyboard, "up", "p1ThrowBomb();","");
gameActionMap.bind(keyboard, "left", "p1MoveLeft");
gameActionMap.bind(keyboard, "right", "p1MoveRight");
gameActionMap.bind(keyboard, "g", "p1MoveUp");
gameActionMap.bind(keyboard, "down", "p1MoveDown");
}Oddly, the game continued running using the previous set of binds (with up moving up). I figured there must be something slightly screwy going on somewhere, so decided to have a hunt around.I found that in \common\preferences there is a file called bind.cs. I haven't been through the source to see where this gets created, but it overwrites any keybindings you try and set through script. After deleting it a few times, my new keybindings finally took.
I think what may have happened is that I have a tendancy to bring down the console and type 'quit();' rather than exit gracefully. So maybe that file wasn't getting updated properly when the game shut down.
Still, now I know I can delete it into submission, I'll just add it to the cleandso.bat file :)
Torque 3D Owner Tom Ogburn
Starlit Sky Games
to activate the actionmap.