[resolved]mouseUp works on 1, but not 2 or 3 question
by rennie moffat · in Torque Game Builder · 02/23/2010 (1:11 am) · 16 replies
i have a onMouseEvent in a behavior which the owner is a button.
this mouseUp event is supposed to trigger a dismount which ever object, 1, 2, or 3 is mounted to the player. It works for object 1, but not 2 and thus not 3, as i cant get to 3, if i cant dismount 2.
my code is this..
this, is surprisingly only dismounts 1, when i pick up and go to dismount 2 it does not work. why would that be? Is there another way to manage which objects are effected in a single event?
this mouseUp event is supposed to trigger a dismount which ever object, 1, 2, or 3 is mounted to the player. It works for object 1, but not 2 and thus not 3, as i cant get to 3, if i cant dismount 2.
my code is this..
onMouseUp()
{
if(isObject($this1)
{
if($this1Mounted == true)
{
$this1.dismount();
}
}
if(isObject($this2)
{
if($this2Mounted == true)
{
$this2.dismount();
}
}
if(isObject($this3)
{
if($this3Mounted == true)
{
$this3.dismount();
}
}
}this, is surprisingly only dismounts 1, when i pick up and go to dismount 2 it does not work. why would that be? Is there another way to manage which objects are effected in a single event?
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
02/23/2010 (1:24 am)
If the second and third ones aren't working, try to find out which if-statement is causing the problem. The easiest way is to put echo statements inside each if-statement. Then you can tell whether or not it is the isObject that is failing or the $this*Mounted that is failing.
#3
so i placed some echos in, on isMOunted it returned 1, on isObject it returned zero, so I removed isObject, tho it seems very odd, since that object is declared as a behavior field and as a global variable in it own behavior.
I then placed an echo in for the dismount method. and it says for starsStar2, that on that line of code, it is a void call.
I dont get it.
02/23/2010 (11:39 am)
ok, sorry about that code, i had switched computers and it was at that time very late, but you got the idea.so i placed some echos in, on isMOunted it returned 1, on isObject it returned zero, so I removed isObject, tho it seems very odd, since that object is declared as a behavior field and as a global variable in it own behavior.
I then placed an echo in for the dismount method. and it says for starsStar2, that on that line of code, it is a void call.
I dont get it.
function starDismountBtn::onMouseUp(%this, %mod, %worldPos, %mouseClicks)
{
if($starsStar1Mounted == true)
{
echo($starsStar1Mounted);
%this.starsStar1.dismount();
%this.starsStar1.setLinearVelocityY(%this.gravity);
}
if($starsStar2Mounted == true)
{
echo($starsStar2Mounted);
%this.starsStar2.dismount();
%this.starsStar2.setLinearVelocityY(%this.gravity);
}
if($starsStar3Mounted == true)
{
echo($starsStar3Mounted);
%this.starsStar3.dismount();
%this.starsStar3.setLinearVelocityY(%this.gravity);
}
}
#4
now, i use an onUpdate to see, when to allow, use mouse events, so my on update is like this. perhaps this is where the problem is, but i am unsure why.
02/23/2010 (11:45 am)
sorry it actually says "call to dismount in onMouseUp uses the result of a void function call.now, i use an onUpdate to see, when to allow, use mouse events, so my on update is like this. perhaps this is where the problem is, but i am unsure why.
function starDismountBtn::onUpdate(%this)
{
if($starsStar1Mounted == true)
{
%this.owner.setUseMouseEvents(true);
}
if($starsStar2Mounted == true)
{
%this.owner.setUseMouseEvents(true);
}
if($starsStar3Mounted == true)
{
%this.owner.setUseMouseEvents(true);
}
}
#5
it says that this line is the result of a void function call. I am wondering is it the echo itself that is void or the call to dismount?
onMouseUp...
02/23/2010 (12:33 pm)
Yes, I have placed this inside the function onMouseUp inside the if($starsStar2Mounted == true)...echo(%this.starsStar2.dismount());
it says that this line is the result of a void function call. I am wondering is it the echo itself that is void or the call to dismount?
onMouseUp...
if($starsStar2Mounted == true)
{
echo($starsStar2Mounted);
%this.starsStar2.dismount();
echo(%this.starsStar2.dismount());
%this.starsStar2.setLinearVelocityY(%this.gravity);
}
#6
thanks so much.
02/23/2010 (12:53 pm)
I hate to do this, but this is my entire code for the behavior, if you can please, if there is, spot the problem.thanks so much.
if(!isObject(starDismountBtn))
{
%template = new BehaviorTemplate(starDismountBtn);
%template.friendlyName = "star dimount btn";
%template.description = "allows star to dismount";
%template.behaviorType = "input";
%template.addBehaviorField(starsStar1, "", object, "", t2dSceneObject);
%template.addBehaviorField(starsStar2, "", object, "", t2dSceneObject);
%template.addBehaviorField(starsStar3, "", object, "", t2dSceneObject);
%template.addBehaviorField(gravity, "", float, "");
}
function starDismountBtn::onBehaviorAdd(%this)
{
%this.owner.enableUpdateCallback();
}
function starDismountBtn::onUpdate(%this)
{
%this.checkIfStarHasItsStar();
}
function starDismountBtn::checkIfStarHasItsStar(%this)
{
if($starsStar1Mounted == true)
{
%this.owner.setUseMouseEvents(true);
}
if($starsStar2Mounted == true)
{
%this.owner.setUseMouseEvents(true);
}
if($starsStar3Mounted == true)
{
%this.owner.setUseMouseEvents(true);
}
}
function starDismountBtn::onMouseUp(%this, %mod, %worldPos, %mouseClicks)
{
if($starsStar1Mounted == true)
{
echo($starsStar1Mounted);
%this.starsStar1.dismount();
%this.starsStar1.setLinearVelocityY(%this.gravity);
}
if($starsStar2Mounted == true)
{
echo($starsStar2Mounted);
%this.starsStar2.dismount();
echo(%this.starsStar2.dismount());
%this.starsStar2.setLinearVelocityY(%this.gravity);
}
if($starsStar3Mounted == true)
{
echo($starsStar3Mounted);
%this.starsStar3.dismount();
%this.starsStar3.setLinearVelocityY(%this.gravity);
}
}
#7
To make your echo statements useful, it's best to have additional data printed out with them.
Right now, your onMouseUp will either print nothing or a single "1". A bette way to determine what portions of the code are working and what portions are not working would be to change it to something like this:
02/23/2010 (12:53 pm)
[THIS IS ORDERED WRONG! HOW COULD THIS HAPPEN? ANYWAY... THIS CAME AFTER YOUR POST #6.]To make your echo statements useful, it's best to have additional data printed out with them.
Right now, your onMouseUp will either print nothing or a single "1". A bette way to determine what portions of the code are working and what portions are not working would be to change it to something like this:
function starDismountBtn::onMouseUp(%this, %mod, %worldPos, %mouseClicks)
{
echo( "In starDismountBtn::onMouseUp." );
echo( " StarsStar1Mounted? " @ $starsStar1Mounted );
echo( " StarsStar2Mounted? " @ $starsStar2Mounted );
echo( " StarsStar3Mounted? " @ $starsStar3Mounted );
if($starsStar1Mounted)
{
%this.starsStar1.dismount();
%this.starsStar1.setLinearVelocityY(%this.gravity);
}
if($starsStar2Mounted)
{
%this.starsStar2.dismount();
%this.starsStar2.setLinearVelocityY(%this.gravity);
}
if($starsStar3Mounted)
{
%this.starsStar3.dismount();
%this.starsStar3.setLinearVelocityY(%this.gravity);
}
}
#8
thanks I have used those new, to me, echo techniques, much easier to spot and read, thank you.
I still have not got this to work, and I am not sure why. I placed this echo code in, it returns that "call to dismount in onMouseUp uses result of void function call. I am unsure if this echo is the problem or the echo is pointing to the problem.
02/23/2010 (3:08 pm)
@ william, thanks I have used those new, to me, echo techniques, much easier to spot and read, thank you.
I still have not got this to work, and I am not sure why. I placed this echo code in, it returns that "call to dismount in onMouseUp uses result of void function call. I am unsure if this echo is the problem or the echo is pointing to the problem.
if($starsStar2Mounted == true)
{
%this.starsStar2.dismount();
echo(%this.starsStar2.dismount());
%this.starsStar2.setLinearVelocityY(%this.gravity);
}
#9
02/24/2010 (1:58 am)
The function "dismount" doesn't return anything that echo could print out.
#10
02/24/2010 (6:19 am)
right, but why would it be void tho? to me thats sounds negative, like i did something wrong. Beyond that, the way I have called it in an echo, is that correct, incorrect, or redundant, since it cannot return anything?
#11
If you have a book on C or C++, you should research "void" in that.
02/24/2010 (11:43 am)
If you get an error message, you did something wrong. That's what error message are for.If you have a book on C or C++, you should research "void" in that.
#12
when placing an echo, is it ok to call one like this..
echo(%this.owner.someTypeOfCommandWithBracketsAtEndForAReturn());
is that proper syntax? I Was not sure about the () at the end, inside of an echo and if that may have been the void call or if it was the actual function itself.
02/24/2010 (11:50 am)
ok, i just was not sure if maybe my echo call was wrong. when placing an echo, is it ok to call one like this..
echo(%this.owner.someTypeOfCommandWithBracketsAtEndForAReturn());
is that proper syntax? I Was not sure about the () at the end, inside of an echo and if that may have been the void call or if it was the actual function itself.
#13
02/24/2010 (1:55 pm)
It depends upon what "someTypeOfCommandWithParensAtEndForAReturn()" is. If it returns a value, then echo can print it out. If it doesn't return a value, echo will become confused because it has no clue what you meant for it to do with a "void".echo( %this.owner.getPosition() );works.
echo( %this.owner.enableUpdateCallback() );won't.
#14
William, I am having plenty of trouble with mount().
It works fine in one behavior, but not in another. I know my code is good, as I have checked it, double checked etc. Another reason why i know the code is good, as I replaced..
with say...
and it works for that. I have played with mount positions etc. Would you have any suggestions for better handling mounts?
02/24/2010 (3:03 pm)
I see, thank you.William, I am having plenty of trouble with mount().
It works fine in one behavior, but not in another. I know my code is good, as I have checked it, double checked etc. Another reason why i know the code is good, as I replaced..
%this.owner.mount(); //skipping input for mount
with say...
%this.owner.setLinearVelocity();
and it works for that. I have played with mount positions etc. Would you have any suggestions for better handling mounts?
#15
i found out the reason. I had a game file being called up for the class, that i had forgot about, it was screwing things up.
02/24/2010 (7:58 pm)
@william, i found out the reason. I had a game file being called up for the class, that i had forgot about, it was screwing things up.
#16
best.
02/25/2010 (6:28 am)
@ william. please disregard. The root of my problems were that I had some game files running which were of the same class of the objects in question.best.
Associate William Lee Sims
Machine Code Games