virtually identical behaviors but only one works properly?
by rennie moffat · in Torque Game Builder · 02/01/2010 (2:44 pm) · 6 replies
I have 2 behaviors, they are identical, tho one controls the left button(for player move left) and the other is for the right button(player move right). They are, as I say IDENTICAL, minus, velocityL and velocityR behavior fields and of course behavior names. Both worked, but now, my right button, onMouseUp, does not stop like it is supposed to. I am getting no errors. Is this type of thing common, these type of glitches? Any tips for trouble shooting this?
function rightControl::onMouseUp(%this, %mod, %worldPos, %mouseClicks)
{
%this.Chip.setLinearVelocityX(%this.ChipStop);
}
function rightControl::onMouseUp(%this, %mod, %worldPos, %mouseClicks)
{
%this.Chip.setLinearVelocityX(%this.ChipStop);
}
About the author
My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.
#2
Nice I did not think of that.
What if I had an onCollision for one class.
Would, if I had another need to be onThisCollsion?
02/01/2010 (3:20 pm)
oh I see. Nice I did not think of that.
What if I had an onCollision for one class.
Would, if I had another need to be onThisCollsion?
#3
I tried your method, it did not work so I am thinking that you meant, RightButton (as in right click).
:?
02/01/2010 (3:49 pm)
The one problem here is, these are different objects, button one (left) and button 2, (right). What that means is, imagine two buttons at the bottom of the screen, for an iPhone game. onMouseUp for each button, completely different imageObjects in the editor. I tried your method, it did not work so I am thinking that you meant, RightButton (as in right click).
:?
#4
onMouseUp is correct then for both buttons. As to why one is working and the other isn't, it is a bit difficult to say without seeing more of the behavior code.
02/01/2010 (4:22 pm)
Sorry, I misunderstood your original post - thought you were talking about the mouse buttons and not 2 GUI button elements in your scene.onMouseUp is correct then for both buttons. As to why one is working and the other isn't, it is a bit difficult to say without seeing more of the behavior code.
#5
02/01/2010 (4:24 pm)
right it is strange. as I say, the left works, and the right does not, I have flipped thru them and nothing. ///leftButton
if(!isObject(leftControl))
{
%template = new BehaviorTemplate(leftControl);
%template.friendlyName = "left Movement Button";
%template.description = "by pressing, chip moves right";
%template.behaviorType = "input";
%template.addBehaviorField(velocityL, "velocity of chip moving right", float, -15);
%template.addBehaviorField(ChipStop, "velocity of Chip on mouse up", float, 0);
%template.addBehaviorField(Chip, "chip is the object, that is slave to the pressing of owner", object, "", t2dSceneObject);
}
function leftControl::onBehaviorAdd(%this)
{
%this.owner.setUseMouseEvents(true);
}
function leftControl::onMouseDown( %this, %mod, %worldPos, %mouseClicks)
{
%this.Chip.setLinearVelocityX(%this.velocityL);
}
function leftControl::onMouseUp(%this, %mod, %worldPos, %mouseClicks)
{
%this.Chip.setLinearVelocityX(%this.ChipStop);
}//rightbutton
if(!isObject(rightControl))
{
%template = new BehaviorTemplate(rightControl);
%template.friendlyName = "right Movement Button";
%template.description = "by pressing, chip moves right";
%template.behaviorType = "input";
%template.addBehaviorField(velocityR, "velocity of chip moving right", float, 15);
%template.addBehaviorField(ChipStop, "velocity of Chip on mouse up", float, 0);
%template.addBehaviorField(Chip, "chip is the object, that is slave to the pressing of owner", object, "", t2dSceneObject);
}
function rightControl::onBehaviorAdd(%this)
{
%this.owner.setUseMouseEvents(true);
}
function rightControl::onMouseDown( %this, %mod, %worldPos, %mouseClicks)
{
%this.Chip.setLinearVelocityX(%this.velocityR);
}
function rightControl::onMouseUpRight( %this, %mod, %worldPos, %mouseClicks)
{
%this.Chip.setLinearVelocityX(%this.ChipStop);
}
#6
Next, when something isn't working as you'd expect it to, start adding echo comments in the function to see if it is being called and then check the console to see if those echoes appear.
02/01/2010 (4:32 pm)
Well, first you can change it back to rightControl::onMouseUpNext, when something isn't working as you'd expect it to, start adding echo comments in the function to see if it is being called and then check the console to see if those echoes appear.
function rightControl::onMouseUp( %this, %mod, %worldPos, %mouseClicks)
{
echo("Right Button Released");
%this.Chip.setLinearVelocityX(%this.ChipStop);
}
Associate Mike Lilligreen
Retired T2Der