Binding keyboard keys to actions
by David Sursely · in Torque Game Engine · 11/25/2006 (12:06 am) · 6 replies
I'm trying to make a trigger that binds a keyboard key to a certain action when the player enters a trigger and unbind it when he leaves.
My trigger is called "Treasure"
The function I am binding to the key 'h' is called "LogoAction".
Heres the DataBlock I have for the trigger:
--------------------------------------------------------
datablock TriggerData( Treasure )
{
tickPeriodMS = 100;
};
function Treasure::onEnterTrigger( %this, %trigger, %obj )
{
bindcmd( keyboard, h, LogoAction);
echo( "*******h bound to LogoAction******");
};
function Treasure::onLeaveTrigger( %this, %trigger, %obj )
{
unbind( keyboard, h);
echo( "******h unbound*****");
};
-------------------------------------------------------------
Here's my DataBlock for the LogoItem (containing the "LogoAction" funtion):
---------------------------------------------------------------------------------------
datablock ItemData(TorqueLogoItem)
{
category = "Items";
shapeFile = "~/data/shapes/3dtorquelogo/torque_logo.dts";
};
function LogoAction()
{
MessageBoxYesNo("You found it!!!",
"Would you like to restart?",
"loadMyMission();"
"quit();");
};
------------------------------------------------------------------
As you can see I want a "Yes No" box to pop up when the 'h' is pushed while in the trigger. It's not working. I keep getting script errors when it tried to load these two files. I'm brand new at this and I'm just going off of examples and tutorials and trying to mix and match stuff. If you see what is wrong, help is appreciated.
My trigger is called "Treasure"
The function I am binding to the key 'h' is called "LogoAction".
Heres the DataBlock I have for the trigger:
--------------------------------------------------------
datablock TriggerData( Treasure )
{
tickPeriodMS = 100;
};
function Treasure::onEnterTrigger( %this, %trigger, %obj )
{
bindcmd( keyboard, h, LogoAction);
echo( "*******h bound to LogoAction******");
};
function Treasure::onLeaveTrigger( %this, %trigger, %obj )
{
unbind( keyboard, h);
echo( "******h unbound*****");
};
-------------------------------------------------------------
Here's my DataBlock for the LogoItem (containing the "LogoAction" funtion):
---------------------------------------------------------------------------------------
datablock ItemData(TorqueLogoItem)
{
category = "Items";
shapeFile = "~/data/shapes/3dtorquelogo/torque_logo.dts";
};
function LogoAction()
{
MessageBoxYesNo("You found it!!!",
"Would you like to restart?",
"loadMyMission();"
"quit();");
};
------------------------------------------------------------------
As you can see I want a "Yes No" box to pop up when the 'h' is pushed while in the trigger. It's not working. I keep getting script errors when it tried to load these two files. I'm brand new at this and I'm just going off of examples and tutorials and trying to mix and match stuff. If you see what is wrong, help is appreciated.
#2
datablock TriggerData( Treasure )
{
tickPeriodMS = 100;
};
function Treasure::onEnterTrigger( %this, %trigger, %obj )
{
bindcmd( keyboard, h, LogoAction);
echo( "*******h bound to LogoAction******");
};
## <------------------------------------------------------------------------------ RIGHT HERE
function Treasure::onLeaveTrigger( %this, %trigger, %obj )
{
unbind( keyboard, h);
echo( "******h unbound*****");
};
Which I thought was a strange place since there is nothing there.
For the LogoItem.cs, it puts HALT MARKS around the last curly bracket, which it also says is at line 12:
datablock ItemData(TorqueLogoItem)
{
category = "Items";
shapeFile = "~/data/shapes/3dtorquelogo/torque_logo.dts";
};
function LogoAction()
{
MessageBoxYesNo("You found it!!!",
"Would you like to restart?",
"loadMyMission();"
"quit();");
##}##; <-----------------------------------------RIGHT HERE
Everything looks ok to me... Anybody else?
11/25/2006 (12:06 pm)
In the console, it says "parse error" when it tries to compile these scripts. It tries to load the trigger first and the logoItem block next. For the triggers.cs it puts the HALT MARKS at line 12:datablock TriggerData( Treasure )
{
tickPeriodMS = 100;
};
function Treasure::onEnterTrigger( %this, %trigger, %obj )
{
bindcmd( keyboard, h, LogoAction);
echo( "*******h bound to LogoAction******");
};
## <------------------------------------------------------------------------------ RIGHT HERE
function Treasure::onLeaveTrigger( %this, %trigger, %obj )
{
unbind( keyboard, h);
echo( "******h unbound*****");
};
Which I thought was a strange place since there is nothing there.
For the LogoItem.cs, it puts HALT MARKS around the last curly bracket, which it also says is at line 12:
datablock ItemData(TorqueLogoItem)
{
category = "Items";
shapeFile = "~/data/shapes/3dtorquelogo/torque_logo.dts";
};
function LogoAction()
{
MessageBoxYesNo("You found it!!!",
"Would you like to restart?",
"loadMyMission();"
"quit();");
##}##; <-----------------------------------------RIGHT HERE
Everything looks ok to me... Anybody else?
#3
In the triggers.cs file I took out the semicolons after the onEnter and onLeave funtions and that one compiles and loads just fine. Then I tried to make my LogoAction function it's own CS file and take it out of the LogoItem.cs DatatBlock file. Now the LogoItem DataBlock compiles and loads just fine, but NOT my new LogoAction.cs function file. Here what the code for the new file looks like:
-------------------------------------------------------
Function LogoAction()
{
MessageBoxYesNo("You found it!!!",
"Would you like to restart?",
"loadMyMission();"
"quit();");
}
-------------------------------------------------------
AND a new problem:
I can now create the trigger called Treasure in the mission editor, and when the player walks into it the console echoes back: "****h bound to LogoAction*****" like it shoud but it also says: "unable to find funtion bindcmd" BindCmd is a console method. Am I allowd to use this command as part of a new funtion that i am creating? Same thing happens when the player leaves the trigger: "unable to find funtion unbind"
11/25/2006 (12:44 pm)
OK, I fixed somethings:In the triggers.cs file I took out the semicolons after the onEnter and onLeave funtions and that one compiles and loads just fine. Then I tried to make my LogoAction function it's own CS file and take it out of the LogoItem.cs DatatBlock file. Now the LogoItem DataBlock compiles and loads just fine, but NOT my new LogoAction.cs function file. Here what the code for the new file looks like:
-------------------------------------------------------
Function LogoAction()
{
MessageBoxYesNo("You found it!!!",
"Would you like to restart?",
"loadMyMission();"
"quit();");
}
-------------------------------------------------------
AND a new problem:
I can now create the trigger called Treasure in the mission editor, and when the player walks into it the console echoes back: "****h bound to LogoAction*****" like it shoud but it also says: "unable to find funtion bindcmd" BindCmd is a console method. Am I allowd to use this command as part of a new funtion that i am creating? Same thing happens when the player leaves the trigger: "unable to find funtion unbind"
#4
11/25/2006 (8:41 pm)
OK, I was getting ahead of myself with the Binding issue. I got to the point in the book that talks about declaring an action map and using the Bind method with the ActionMap Name.... Now Im off to go try!!! Still have to figure out why my LogoAction function isnt working...
#5
Look in "yourGame/client/scripts/default.bind.cs" as it shows you the proper way to bind a key.
11/26/2006 (7:02 am)
You are binding the keyboard wrong. Look in "yourGame/client/scripts/default.bind.cs" as it shows you the proper way to bind a key.
#6
11/26/2006 (11:15 am)
Yeah thanks, I got the binding down now... But my LogoAction function still doesn't work. I have no idea why.
Torque Owner Christopher Harris