If "keypressed
by Kiyaku · in Torque Game Engine Advanced · 04/07/2008 (7:45 am) · 5 replies
Hi there,
is there something like "keyPressed" or whatever?
If i want a door to open when im close to her and checking the distance by vectorDist i would also like to check if i pressed a key.
How would i write that?
is there something like "keyPressed" or whatever?
If i want a door to open when im close to her and checking the distance by vectorDist i would also like to check if i pressed a key.
[...]
if(vectorDist(%obj.getPosition(), $playerPtr.getPosition()) < 5 && keyPressed...)
{
openDoor();
}How would i write that?
#2
If i have to use action maps, i'm thinking about a good way for creating a "use" key to do many different actions like open doors, click a lightswitch, etc.
I would probably write a function "useAction" or something and bind that to the "e" key. In this function i would set a variable "usedActionKey" to 1 and change it back to 0 after few miliseconds.
So i could write my code like:
Would this be a good solution or are there any better "tricks"?
Thanks in advance!
04/07/2008 (8:36 am)
So i always have to use action maps for checkings keys or is it possible to ask it inside a function?If i have to use action maps, i'm thinking about a good way for creating a "use" key to do many different actions like open doors, click a lightswitch, etc.
I would probably write a function "useAction" or something and bind that to the "e" key. In this function i would set a variable "usedActionKey" to 1 and change it back to 0 after few miliseconds.
So i could write my code like:
if(vectorDist(%obj.getPosition(), $playerPtr.getPosition()) < 5 && $usedActionKey)
{
openDoor();
}Would this be a good solution or are there any better "tricks"?
Thanks in advance!
#3
In a client script, like default.bind.cs
In a server script, like server\scripts\commands.cs
The only issue I see is where you get the %obj. Other than that, sounds like a good start.
04/08/2008 (6:42 am)
Sounds like you are off to a good start Kiyaku. If I can make one suggestion, I would create the binding and function call on the client side, and the "guts" of your functionality on the server side:In a client script, like default.bind.cs
moveMap.bindCmd(keyboard, "e", "commandToServer('useAction', true);", "");In a server script, like server\scripts\commands.cs
function serverCmduseAction(%client, %active)
{
if(vectorDist(%obj.getPosition(), %client.player.getPosition()) < 5 && %active)
{
openDoor();
}
}The only issue I see is where you get the %obj. Other than that, sounds like a good start.
#4
origin-www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=13640
04/08/2008 (8:45 am)
I made a resource that casts a ray after pressing a button and then performs an action after that.origin-www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=13640
#5
Though i didn't use the Server Commands yet as you stated, michael. I couldn't get it to work and i didn't check the multiplayer parts yet but will do that soon and try to rewrite it.
04/08/2008 (10:52 am)
Thanks a lot, i managed to finally finished the "use" and "trace" function and it works perfectly.Though i didn't use the Server Commands yet as you stated, michael. I couldn't get it to work and i didn't check the multiplayer parts yet but will do that soon and try to rewrite it.
Employee Michael Perry
ZombieShortbus
This script shows you how to create an action map and keybindings for calling methods you write.