bindObj() vs. bindCmd()
by Rob Cain · in Torque Game Builder · 06/07/2010 (9:30 am) · 5 replies
bindObj() and bindCmd() clearly do different things but I don't have access to the source and the inputs aren't very descriptive. All the scripting tutorials use bindCmd() to set up controls, but behavior tutorials all use bindObj(). Can someone fill me in on the difference?
About the author
#2
For example, in the following use:
the moveLeft() function takes a %val which I assume is for the 0 and 1 above, which would place 0 as "not pressed" and 1 as "pressed". Am I right? Could I then do the following to run different commands for key up and key down:
...Or would I have to do the following:
?
06/07/2010 (9:57 am)
@Daniel: Okay. So what are the "[modifier spec, mod...]" arguments for? It looks like they can field multiple possible values but I'm not sure what they mean.For example, in the following use:
moveMap.bindObj(getWord(%this.leftKey, 0), getWord(%this.leftKey, 1), "moveLeft", %this);
the moveLeft() function takes a %val which I assume is for the 0 and 1 above, which would place 0 as "not pressed" and 1 as "pressed". Am I right? Could I then do the following to run different commands for key up and key down:
moveMap.bindObj(getWord(%this.jumpKey, 1), "jump", %this); moveMap.bindObj(getWord(%this.jumpKey, 0), "jumpHalt", %this);
...Or would I have to do the following:
moveMap.bindObj(getWord(%this.jumpKey, 0), getWord(%this.jumpKey, 1), "jumpControl", %this);
// Later...
function Behavior::jumpControl(%this, %val)
{
if (%val) {
jump();
} else {
jumpHalt();
}
}?
#3
EDIT - to explain, the getword(%something, 0) function is grabbing the first element in the array of %something (the safe name, I think), then getword(%something, 1) is grabbing the second element (the keyboard binding.)
It has nothing to do with true/false.
Just a heads up, jump(); probably needs to be %this.owner.jump(); assuming your player is the object with the jump method. %this refers to the behavior, %this.owner refers to the object with the behavior attached to it. You want your player jumping, not your abstract behavior ;)
06/07/2010 (12:57 pm)
The second option will work I think. You seem confused on the usage of getWord(). EDIT - to explain, the getword(%something, 0) function is grabbing the first element in the array of %something (the safe name, I think), then getword(%something, 1) is grabbing the second element (the keyboard binding.)
It has nothing to do with true/false.
Just a heads up, jump(); probably needs to be %this.owner.jump(); assuming your player is the object with the jump method. %this refers to the behavior, %this.owner refers to the object with the behavior attached to it. You want your player jumping, not your abstract behavior ;)
#4
06/07/2010 (1:00 pm)
getWord() is a little confusing too. From what I've seen in my studies today I think jump() would need to be %this.jump(), with the function itself directing %this.owner's activity. Otherwise, if the owner didn't have a jump() function the game would crash; whereas the Behavior will have that function.
#5
bind the function to "moveLeft". MoveLeft HAS to exist in the behavior.cs file, otherwise nothign will happen.
inside of moveLeft, you can make calls to %this.owner.doSomething();
If the owner of the behavior doesn't have doSomething() defined, it won't do anything but give warnings. If it IS defined, it will execute it.
You need to make sure you assign this behavior to objects that you KNOW will have certain methods.
If the owner doesn't have a jump method, why are you giving it a jump behavior?
06/07/2010 (1:04 pm)
Rob, don't worry about behaviors calling functions that don't exist. For example:bind the function to "moveLeft". MoveLeft HAS to exist in the behavior.cs file, otherwise nothign will happen.
inside of moveLeft, you can make calls to %this.owner.doSomething();
If the owner of the behavior doesn't have doSomething() defined, it won't do anything but give warnings. If it IS defined, it will execute it.
You need to make sure you assign this behavior to objects that you KNOW will have certain methods.
If the owner doesn't have a jump method, why are you giving it a jump behavior?
Torque 3D Owner Daniel Balmert
Default Studio Name
bindCmd(): Binds a function to a key press and key release