Game Development Community

Bind issues

by Samuel Marcus · in Torque Game Builder · 11/12/2006 (2:15 am) · 5 replies

Because everyone enjoys bind issues...

When I use

moveMap.bind(keyboard,"q","function1();");
	moveMap.bind(keyboard,"w","function2();");

And then press q or w (or whatever you want to set) I get "Unknown Command" errors.

Now, I've established that this is because the object that function1 and 2 belong to was created as a ScriptObject-- if I use a function like getID() or some other built-in call, it will work fine. But I've defined function1 and 2 as functions for my object-- why can't the moveMap see them? The Game can; other objects can.... but moveMap can't see thre functions even if I give my ScriptObject a $Name and refer to it in the function call. Are ScriptObjects just bad news?

#1
11/12/2006 (2:19 am)
Er.. that's what I thought the issue was, anyway. I converted it to a t2dSceneObject and the same thing is happening. bindCMD(...) is acting similarly (but with more arguments).
#2
11/12/2006 (11:42 am)
Ok so it seems that you can only bind class-less functions to keys. Is that the case?
#3
11/12/2006 (2:57 pm)
If you want to bind a function that is part of something other than the global namespace then you'll have to include the namespace in the bind.
#4
11/12/2006 (3:33 pm)
Thanks!
#5
11/12/2006 (3:41 pm)
When using "bind" you don't include braces or the semi-colon

moveMap.bind(keyboard, "q", function1 );

function1 in this case should accept a "%val" parameter that will be true on keypress and false on key release.

For "bindCmd" you specify a script command to run on keydown and another to run on key up. This could be a function call

moveMap.bindCmd(keyboard, "q", "function1OnPress();", "function1OnRelease();" );

or several separate commands.

moveMap.bindCmd(keyboard, "q", "function1OnPress();doMoreStuff();", "function1OnRelease();" );

You can also call methods on named objects or those you have a reference to such as

// named object
moveMap.bindCmd(keyboard, "s", "player1.moveDown(1);", "player1.moveDown(0)" );
// object using global var
moveMap.bindCmd(keyboard, "space", "$player.spawn(1);", "$player.moveDown(0)" );

where moveDown is a function in the player1 (or the class your player1 is) namespace and 1/0 is a parameter to indicate key press/key release to save having to have a separate moveDown and moveDownStop function.