Keymaps
by Adam · in Torque Game Engine · 09/01/2006 (9:30 am) · 6 replies
I want to allow the user to switch key configurations during game play. What I did is edit default.bind.cs like this.
My secondMoveMap.cs looks like this
Now this is my client.cs/init
Now this is what I get when the q key is pressed once
Switching to Second Key Map
Loading compiled script starter.fps/client/scripts/secondMoveMap.cs.
Switching to default key map
Loading compiled script starter.fps/client/scripts/default.bind.cs.
Then I loose all ablility to press keys at all except for the ~
Should I be doing this differently? When a file called with exec does it start from the top of the file again, I ask this because maybe moveMap is not getting deleted and initialized correctly.
Thanks in advance.
function switchKeyMaps(%val)
{
echo("Switching to Second Key Map");
exec("./secondMoveMap.cs");
}
moveMap.bind( keyboard, q, switchKeyMaps );My secondMoveMap.cs looks like this
//First delete the old Action map
if ( isObject( moveMap ) )
moveMap.delete();
new ActionMap(moveMap);
//Create functions for moving
function moveleft(%val)
{
$mvLeftAction = %val * $movementSpeed;
}
function moveright(%val)
{
$mvRightAction = %val * $movementSpeed;
}
function moveforward(%val)
{
$mvForwardAction = %val * $movementSpeed;
}
function movebackward(%val)
{
$mvBackwardAction = %val * $movementSpeed;
}
function switchKeyMaps(%val)
{
echo("Switching to default key map");
exec("./default.bind.cs");
}
//===========================================
//Key bindings
//===========================================
moveMap.bind( keyboard, left, moveleft );
moveMap.bind( keyboard, right, moveright );
moveMap.bind( keyboard, up, moveforward );
moveMap.bind( keyboard, down, movebackward );
moveMap.bind( keyboard, q, "switchKeyMaps" );Now this is my client.cs/init
// Default player key bindings
//exec("./scripts/secondMoveMap.bind.cs");
exec("./scripts/default.bind.cs");
// exec("./config.cs");Now this is what I get when the q key is pressed once
Switching to Second Key Map
Loading compiled script starter.fps/client/scripts/secondMoveMap.cs.
Switching to default key map
Loading compiled script starter.fps/client/scripts/default.bind.cs.
Then I loose all ablility to press keys at all except for the ~
Should I be doing this differently? When a file called with exec does it start from the top of the file again, I ask this because maybe moveMap is not getting deleted and initialized correctly.
Thanks in advance.
About the author
#2
Use
to push and pop different keymaps.
Lastly, change the name of your new keymap and make sure the bind cmd name matches.
E.g.
Instead of:
Use:
You can also use this function to unbind individual cmds:
09/01/2006 (10:06 am)
Firstly, rather than execute the new keymap script on the fly execute both scripts on startup. I.e. default.bind.cs and your new one. Use
movemap.pushand
movemap.pop
to push and pop different keymaps.
Lastly, change the name of your new keymap and make sure the bind cmd name matches.
E.g.
Instead of:
//First delete the old Action map if ( isObject( moveMap ) ) moveMap.delete(); new ActionMap(moveMap); moveMap.bind( keyboard, left, moveleft );Which is already used / reserved for default.bind.cs
Use:
//First delete the old Action map if ( isObject( MyMoveMap ) ) MyMoveMap.delete(); new ActionMap(MyMoveMap); MyMoveMap.bind( keyboard, left, moveleft );
You can also use this function to unbind individual cmds:
moveMap.unbind( %device, %action );E.g.
moveMap.unbind( keyboard, x );
#3
That really helps a lot, I really appreciate you taking the time to break that down for me.
I guess the only part I am still lost on is switching between the two keymaps.
1. I'll load both scripts in client/init.cs
Now since I have two ActionMaps defined do I just call
moveMap.push() to make that the active one and then moveMap.pop() to remove it.
Then all I would have to do is call secondMoveMap.push() to make the second one the active ActionMap.
Thanks again for all the help
Surge
That is a very useful link that will come in handy in the future.
09/01/2006 (10:43 am)
TimThat really helps a lot, I really appreciate you taking the time to break that down for me.
I guess the only part I am still lost on is switching between the two keymaps.
1. I'll load both scripts in client/init.cs
Now since I have two ActionMaps defined do I just call
moveMap.push() to make that the active one and then moveMap.pop() to remove it.
Then all I would have to do is call secondMoveMap.push() to make the second one the active ActionMap.
Thanks again for all the help
Surge
That is a very useful link that will come in handy in the future.
#4
Thanks again
09/01/2006 (10:48 am)
I just got it working perfectly. I ended up binding a single key in each actionmap to pop the current keymap and the push the new one.Thanks again
#5
Now, to switch maps you would use moveMap.pop() to remove the default.bind.cs map and myMoveMap.push() to inititate the new map you created. Do the reverse to remove your new map and resort to the one in default.bind.cs.
Really shouldn't take any more than a few lines of code. Much more effecient than what you were doing above.
If you still need help just yell out.
09/01/2006 (10:50 am)
Yes, load both scripts in client/init.csNow, to switch maps you would use moveMap.pop() to remove the default.bind.cs map and myMoveMap.push() to inititate the new map you created. Do the reverse to remove your new map and resort to the one in default.bind.cs.
Really shouldn't take any more than a few lines of code. Much more effecient than what you were doing above.
If you still need help just yell out.
#6
function BLABLA()
{
%command
if keypressed;
then get(%command);
}
dont know if thats it but im not very good at c++ so dont really know f thats right
10/07/2006 (9:33 am)
I think it should be like this though i dont know if this C/C++ code is used in torque:function BLABLA()
{
%command
if keypressed;
then get(%command);
}
dont know if thats it but im not very good at c++ so dont really know f thats right
Torque Owner Surge
MDNAMEDIA
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10961