Game Development Community

echo not called inside mouse function

by rennie moffat · in Torque Game Builder · 12/14/2009 (3:46 pm) · 6 replies

Hi, I realise this is a programming question but I have a behavior where functions are being called, as I have placed echos insode each, until I get to my mouseDown function. It does not call the echo. I am not sure why. Is there a common reason, can someone see why it is not being called. Thanks.


if (!isObject(CubeOnMouseDownBehavior))
{
   %template = new BehaviorTemplate(CubeOnMouseDownBehavior);
   
   %template.friendlyName = "Cube Moves to Clicked pt on MouseDown";
   %template.behaviorType = "Mouse Input";
   %template.description  = "Moves the object to MousePosition on mouse down";
   
   %template.addBehaviorField(cubeSpeed, "The speed at which the object moves.", float, 45.0);

}

function CubeOnMouseDownBehavior::onBehaviorAdd(%this, %scenegraph)
{
	%this.owner.setUseMouseEvents(true);
	echo("---inside onBeAdd We are");
	
}


echo("---ouside before MouseDown We are");


function CubeOnMouseDownBehavior::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{
	echo("---InsideMouseDown We are");
///this echo is not seen in the console.log
}

echo("---outside after MouseDown We are");
///this is tho. ?

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.


#1
12/14/2009 (3:59 pm)
you need to click on the object in the scene that has that class to call the onMouseDown method.
#2
12/14/2009 (4:16 pm)
ok,
but I am talking about the console.log, i tried it with the game running and not, I clicked on the object while the game was running and nothing appeared in the console.log.


So I am stuck.
#3
12/17/2009 (11:59 am)
Hi,

I simply copied your code into my project, assigned the behavior to an object. You are right, no output of this line in the console log. However, I am using Torsion, and the echo output is written in its log window, which listens to the port 6060. So your code is alright, I think.
#4
12/17/2009 (1:12 pm)
interesting.
So is that just some sort of glitch? in other words I dont have to have echos to prove me right. in other words keep on trucking until i see something wrong, use discretion?
#5
12/21/2009 (3:06 pm)
This code copied straight from here and applied to an object with "_behavior1 = "CubeOnMouseDownBehavior";" works just fine for me. The echo shows up in the console.log no problem.

Since there is NOTHING else going on inside the function, it's hard to tell if it is even being run... I suggest a breakpoint to make sure (if not using Torsion, I guess just throw some code in there like "%this.owner.setblendcolor("1 1 0 1");" to check and make sure it is even running.

My guess is that it is not, which means something is wrong with either the object (not visible, no collision detection, etc.) or the way that you assign the behavior to the object.

#6
12/21/2009 (3:09 pm)
It's also worth noting that echo statements OUTSIDE of functions in a script like you have there will be called when that script is called up by exec()... Not when the mouse is clicked.

So when you run your game you'll get one each of the 'before' and 'after' echoes, and you'll never see those echoes again.

Your placement of them makes me think that might be something you are misunderstanding a bit?

-Tim