Keyboard input
by Daniel Brown · in Torque Game Engine · 04/09/2004 (2:41 am) · 4 replies
This maybe incredibly simple but i can't find it in the documents anywhere..
..but what is the command for detecting if a key is being pressed? I have 2 modes and i want to switch between when you press the space key. I just need a command that will change a variable if a key has been pressed.
Thanks for any help.
..but what is the command for detecting if a key is being pressed? I have 2 modes and i want to switch between when you press the space key. I just need a command that will change a variable if a key has been pressed.
Thanks for any help.
About the author
#2
Then in movemanager.cc is where it sets up those script variables and reads them (to pack into a move structure).
04/09/2004 (3:52 am)
Default.bind.cs has a number of the key mappings.. it shows how to use a script variable bound to a key.Then in movemanager.cc is where it sets up those script variables and reads them (to pack into a move structure).
#3
04/09/2004 (3:58 am)
Thanks, ive put all that in, but for some reason, any functions i create in default.bind.cs cant be found when im in the game? is there something im missing?
#4
1) In the first portion, at demo/server/game.cs, you defined a variable "HasFlag" when the player is created. The HasFlag variable can be changed to any suitable name and in this case is initialised as 0.
%player.HasFlag=0;
2) At demo/client/default.bind.cs, you will need to create a function like the b/m.
Notice that you have a function 'mountFlag' (client side) which allows you to activate a function 'MountFlag' (at the server side)
function mountFlag(%val)
{
if (%val)
commandToServer('MountFlag');
}
This b/m statement will bind the key '1' and activate the function whenever key '1' is pressed
moveMap.bind( keyboard, "1", mountFlag);
3) At demo/server/commands.cs or demo/server/script/commands.cs, you will see that the server function has an additional 'serverCmd' prepend to the word 'MountFlag'. What the b/m function does is that it toggles that Player's HasFlag variable while executing some unmountImage() and mountImage function.
function serverCmdMountFlag(%client)
{
if (%client.player.HasFlag){
%client.player.unmountImage(0);
%client.player.HasFlag=0;
}else{
%client.player.mountImage(FlagPoleImage,0);
%client.player.HasFlag=1;
}
}
Note that the above also applies if you are doing a single player game because Torque works in a "client/server" way.
04/09/2004 (7:53 am)
Sorry, my first reply is incomplete.1) In the first portion, at demo/server/game.cs, you defined a variable "HasFlag" when the player is created. The HasFlag variable can be changed to any suitable name and in this case is initialised as 0.
%player.HasFlag=0;
2) At demo/client/default.bind.cs, you will need to create a function like the b/m.
Notice that you have a function 'mountFlag' (client side) which allows you to activate a function 'MountFlag' (at the server side)
function mountFlag(%val)
{
if (%val)
commandToServer('MountFlag');
}
This b/m statement will bind the key '1' and activate the function whenever key '1' is pressed
moveMap.bind( keyboard, "1", mountFlag);
3) At demo/server/commands.cs or demo/server/script/commands.cs, you will see that the server function has an additional 'serverCmd' prepend to the word 'MountFlag'. What the b/m function does is that it toggles that Player's HasFlag variable while executing some unmountImage() and mountImage function.
function serverCmdMountFlag(%client)
{
if (%client.player.HasFlag){
%client.player.unmountImage(0);
%client.player.HasFlag=0;
}else{
%client.player.mountImage(FlagPoleImage,0);
%client.player.HasFlag=1;
}
}
Note that the above also applies if you are doing a single player game because Torque works in a "client/server" way.
Torque Owner James Yong
the bold text is added.
function GameConnection::createPlayer(%this, %spawnPoint)
{
if (%this.player > 0) {
// The client should not have a player currently
// assigned. Assigning a new one could result in
// a player ghost.
error( "Attempting to create an angus ghost!" );
}
// Create the player object
%player = new Player() {
dataBlock = PlayerShape;
client = %this;
};
%player.HasFlag=0;
MissionCleanup.add(%player);
Append the following to demo/client/default.bind.cs
function mountFlag(%val)
{
if (%val)
commandToServer('MountFlag');
}
moveMap.bind( keyboard, "1", mountFlag);
Create a new demo/server/commands.cs file having the following content.
function serverCmdMountFlag(%client)
{
if (%client.player.HasFlag){
%client.player.unmountImage(0);
%client.player.HasFlag=0;
}else{
%client.player.mountImage(FlagPoleImage,0);
%client.player.HasFlag=1;
}
}
-James Yong