Game Development Community

Passing data between objects problem

by Alex Moran · in Torque Game Builder · 10/23/2007 (1:57 am) · 11 replies

Can someone please explain to me why this function does not work and how I can fix it? I am trying to manipulate one object when another gets hit. "spoketwo" is the object being manipulated, not the object being collided with.


//
function onCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points)
{
spoketwo.setAngularVelocity(100);
}
//


Thanks.

#1
10/23/2007 (2:19 am)
You'll have to add your object class namespace or your behaviorTemplate namespace.

function ObjectClass::onCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points)
{

}

Or

function BehaviorTemplate::onCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points)
{

}


Aun.
#2
10/23/2007 (2:28 am)
First, made sure that this function to be called when the collision happens. Try to insert echo("COLLISION "); into the body of callback and then check the console during a runtime.
#3
10/23/2007 (11:50 am)
Aun,
adding the object class makes no difference. I added the object class and it still doesn't work.

Dmitriy,
yes the function is called.

Here is another way of putting my question:

Why does this work:
function onCollision(){
spoke.setAngularVelocity(100);}

But not this:
function onCollision(){
spoketwo.setAngularVelocity(100);}

Where "spoke" is the object being collided with and "spoketwo" is another object in the same class.
?
#4
10/23/2007 (2:16 pm)
Does spokeTwo have collision callbacks turned on? This can be done through the Editor or through code.
#5
10/23/2007 (4:13 pm)
Yes, they both have collision callbacks turned on. Both objects are identical in all respects except their names.
#6
10/23/2007 (8:18 pm)
Thats because you have two functions with the same name and no class variation. You cannot have two functions with the same name, unless they belong to different classes.

I have no idea why you wouldn't just use the onCollision function with the parameters and just used the %srcObject and %dstObject parameters to apply the velocities.

I think you have a big problem with your logic.
#7
10/23/2007 (9:04 pm)
Thanks for the input Phillip, but I don't think you understand what I'm trying to do. I have only one function (onCollision), and three objects. When two of them collide I want the third object to do something. From what I understand %srcObject and %dstObject only refer to the objects involved in the collision.

If anyone could describe how to make the collision of two objects affect a third object I would very much appreciate it. As far as I can tell the method built into TorqueScript does not work. I am using the latest version TGB (1.5.1?) on the mac.

Thanks.
#8
10/23/2007 (9:22 pm)
Ahhh, okay, I *think* I understand what you're doing now.

Have you tried typing the command into the console directly? i.e. just type "spoketwo.setAngularVelocity(100);"

Failing this, check the console.log to see if there are any error messages being reported. It may not even be able to find the object in question.
#9
10/24/2007 (12:15 am)
The console didn't return any errors. I started over and now it works. I did everything the same.....
#10
10/24/2007 (8:07 am)
Alex, I like to put in most functions what is being called and echoing it to the console. It's a little tiring, but when I know that it's all working properly, I strip or disable all of that.
#11
10/24/2007 (9:06 am)
Glad the problem is resolved.

I use echo's as well. As I'm still learning, I may have some incorrect syntax. It's a great way to know if my function or callback is actually getting called.

Just this week I made a little GUI control in mainScreen allowing me to write out statements directly to my game screen. Nothing more than a semi-transparent GUI control with a text control, but I sometimes want immediate feedback without having to head to the console.