Using scriptobject to handle mouse input
by Charles "monkeyboy" Gibson · in Torque Game Builder · 05/05/2008 (9:12 am) · 3 replies
Hi,
I am trying to bind the left mouse button and y-axis to methods of a script object. I don't have to code on me at the moment, but here is an example of what I was doing. When I get home tonight, I will post it if it is needed.
So I define an input controller to be used as a scriptobject. I define a method called "bind" that sets up the bindings for the controller.
Then I define the handler below as such.
Elsewhere in my application I create a scriptobject using MouseController as the class.
When I check the console.log file, it verifies that it binds the "doSomething" method to the left mouse button, but when I press the left mouse button I never enter the "doSomething" method. Is it possible to peform this type of input handling, or can that only be done with t2dSceneObjects?
Again, I'll post the actual source if it is needed later tonight.
I am trying to bind the left mouse button and y-axis to methods of a script object. I don't have to code on me at the moment, but here is an example of what I was doing. When I get home tonight, I will post it if it is needed.
So I define an input controller to be used as a scriptobject. I define a method called "bind" that sets up the bindings for the controller.
function MouseController::bind(%this)
{
echo("Binding mouse!");
...
actionMap.bindObj(mouse, button0, "doSomething", %this);
...
echo("Verify left mouse binding:" SPC actionMap.getCommand(mouse, button0));
}Then I define the handler below as such.
function MouseController::doSomething(%this, %pressed)
{
echo("I pressed the left mouse button! YAY!");
}Elsewhere in my application I create a scriptobject using MouseController as the class.
%controller = new ScriptObject()
{
class = "MouseController";
};
%controller.bind();When I check the console.log file, it verifies that it binds the "doSomething" method to the left mouse button, but when I press the left mouse button I never enter the "doSomething" method. Is it possible to peform this type of input handling, or can that only be done with t2dSceneObjects?
Again, I'll post the actual source if it is needed later tonight.
About the author
#2
05/06/2008 (6:18 am)
I'm confused. At the same pont that I am trying to bind the mouse actions, I bind keyboard actions. The keyboard actions respond appropriately. Does the keyboard process inputs differently than the mouse or gamepad?
#3
If your gui had a GuiTextEditCtrl, for instance, you wouldn't see your keyboard binds hitting either.
05/06/2008 (9:38 am)
They are processed the same way, and the GUI always has first grabs at input. It just happens that your gui is "consuming" the mouse input but not the keyboard, so thats what is left by the time it gets to your actionmap.If your gui had a GuiTextEditCtrl, for instance, you wouldn't see your keyboard binds hitting either.
Associate James Ford
Sickhead Games
I could be wrong about this - but worth trying out.