How to press anykey?
by Philip Mansfield · in Torque Game Builder · 04/14/2006 (2:46 am) · 7 replies
With the splash screen that displays the T2D logo appears, pressing any key or clicking the mouse will skip past it and onto whatever screen is called next.
I'm trying to duplicate this with some cut-screens in my game. The timer works (so after x time it goes to the next screen) and the click works, but I can't suss the keypresses.
I've setup a specific actionmap for the 'anykey' and I pop the other actionmaps before pushing the anykey one. But pressing a key that's in a different actionmap doesn't seem to register. There must be something that I'm missing, but I'm not sure what.
Failing that, is there something similar to ::click that works for keypresses that I can use?
I'm trying to duplicate this with some cut-screens in my game. The timer works (so after x time it goes to the next screen) and the click works, but I can't suss the keypresses.
I've setup a specific actionmap for the 'anykey' and I pop the other actionmaps before pushing the anykey one. But pressing a key that's in a different actionmap doesn't seem to register. There must be something that I'm missing, but I'm not sure what.
Failing that, is there something similar to ::click that works for keypresses that I can use?
#2
04/14/2006 (5:06 pm)
My next stage is to reorganise my code a bit so I can actually delete the other action maps, push the anykey map, and then recreate my other maps. Bit of a faff, but I've got other more important bits of code to deal with first.
#3
would produce the desired behavior. No idea if it actually works though. :)
04/16/2006 (5:14 pm)
I was looking in the source for the answer to another bindcmd related issue myself and saw that there is actually a command event called 'anykey'. I'm guessing:GlobalActionMap.bindCmd(keyboard, "anykey", "", "myAnyKeyFunction();");
would produce the desired behavior. No idea if it actually works though. :)
#4
04/17/2006 (12:45 am)
I'm using the anykey binding. It's just that it seems to mean 'anykey except for one that has already been assigned in another action map'.
#5
I thought there was a mechanism to push and pop action maps, so you could create/push a new one with just anykey, then pop that off back to your standard action map when the anykey function happens?
04/17/2006 (12:17 pm)
Oh, bummer. So 'anykey' is really 'anyotherkey'...I thought there was a mechanism to push and pop action maps, so you could create/push a new one with just anykey, then pop that off back to your standard action map when the anykey function happens?
#6
So when the game laucnhes, I push the menu action map. Player starts game, I pop the menu map, push the game map. Player gets to cut screen and I run destroyGameControls(). Player presses space to skip the screen, nothing happens (as it's used in the game action map). Player presses 'g' (or any other key not assigned previously) and the screen skips as expected.
04/17/2006 (12:29 pm)
This is how my code currently works:function createGameControls()
{
// if the action maps exist, delete them
if( isObject(gameActionMap) )
gameActionMap.delete();
if( isObject(menuActionMap) )
menuActionMap.delete();
if (isObject(anykeyActionMap) )
anykeyActionMap.delete();
// create a new action map for the game
new ActionMap(gameActionMap);
gameActionMap.bind(keyboard, left, "moveLeft");
gameActionMap.bind(keyboard, right, "moveRight");
gameActionMap.bind(keyboard, up, "moveUp");
gameActionMap.bind(keyboard, space, "jump");
new ActionMap(menuActionMap);
menuActionMap.bindCmd(keyboard, "space", "startGame();", "");
menuActionMap.push();
}
function destroyGameControls()
{
// if the action maps exist, delete them
if( isObject(gameActionMap) )
gameActionMap.delete();
if( isObject(menuActionMap) )
menuActionMap.delete();
if (isObject(anykeyActionMap) )
anykeyActionMap.delete();
new ActionMap(anykeyActionMap);
anykeyActionMap.bindCmd(keyboard, anykey, "anykey();", "");
anykeyActionMap.push();
}So when the game laucnhes, I push the menu action map. Player starts game, I pop the menu map, push the game map. Player gets to cut screen and I run destroyGameControls(). Player presses space to skip the screen, nothing happens (as it's used in the game action map). Player presses 'g' (or any other key not assigned previously) and the screen skips as expected.
#7
First, it takes an input action and loops through the node list of action-mappings until it finds a match. Unfortunately, 'anykey' is not exceptional when it really should be; it's just one more node in the list. So if it first comes across a node that specifically maps the key in question, that'll get found and the loop will stop before the 'anykey' node is found.
Second, it looks at first glance that when you actionMap.push() you aren't blowing away the active map, you're appending to it, and only overwriting assignments that are duplicated in the maps. So what happens in your case is you push the game and menu maps on, and instead of .pop() -ing them off again, you push the anykey action map on, which appends the 'anykey' node to the end of the list, which means it only ever gets found when no other key gets caught first.
So the 'anykey' event is a bit poorly implemented. That said, I think you can fix your problem by creating the ActionMap objects only once and then instead of calling .delete() on the action maps, you need to .pop() them off the active map list, something like this:
The only thing I don't know (and can't test at the moment myself) is if you call .pop() on a map that isn't on the actionMap stack, what'll happen. There doesn't appear to be a command to clear the entire actionMap stack unfortunately, so you may have to code it to be a bit more intelligent on the current state when popping/pushing if the above code doesn't work verbatim.
04/17/2006 (4:28 pm)
Ok, looking at the source code for the actionMap stuff, there seem to be two different issues here.First, it takes an input action and loops through the node list of action-mappings until it finds a match. Unfortunately, 'anykey' is not exceptional when it really should be; it's just one more node in the list. So if it first comes across a node that specifically maps the key in question, that'll get found and the loop will stop before the 'anykey' node is found.
Second, it looks at first glance that when you actionMap.push() you aren't blowing away the active map, you're appending to it, and only overwriting assignments that are duplicated in the maps. So what happens in your case is you push the game and menu maps on, and instead of .pop() -ing them off again, you push the anykey action map on, which appends the 'anykey' node to the end of the list, which means it only ever gets found when no other key gets caught first.
So the 'anykey' event is a bit poorly implemented. That said, I think you can fix your problem by creating the ActionMap objects only once and then instead of calling .delete() on the action maps, you need to .pop() them off the active map list, something like this:
function createGameControls()
{
if(!isObject(gameActionMap))
{
new ActionMap(gameActionMap);
gameActionMap.bind(keyboard, left, "moveLeft");
gameActionMap.bind(keyboard, right, "moveRight");
gameActionMap.bind(keyboard, up, "moveUp");
gameActionMap.bind(keyboard, space, "jump");
}
if(!isObject(menuActionMap))
{
new ActionMap(menuActionMap);
menuActionMap.bindCmd(keyboard, "space", "startGame();", "");
}
if(!isObject(anykeyActionMap))
{
new ActionMap(anykeyActionMap);
anykeyActionMap.bindCmd(keyboard, "anykey", "anykey();", "");
}
}
function activateGameControls()
{
menuActionMap.pop();
anykeyActionMap.pop();
gameActionMap.push();
}
function activateMenuControls()
{
anykeyActionMap.pop();
gameActionMap.pop();
menuActionMap.push();
}
function activateAnykeyControls()
{
menuActionMap.pop();
gameActionMap.pop();
anykeyActionMap.push();
}The only thing I don't know (and can't test at the moment myself) is if you call .pop() on a map that isn't on the actionMap stack, what'll happen. There doesn't appear to be a command to clear the entire actionMap stack unfortunately, so you may have to code it to be a bit more intelligent on the current state when popping/pushing if the above code doesn't work verbatim.
Torque Owner Alex Rice
Default Studio Name
It would be silly if you had to do it, but you could put every single key into your actionmap, and map them to one callback function. A brute force anykey?