Callback only returns "244" instead of a vector.
by MarkusDavey · in Torque 3D Professional · 12/01/2011 (12:09 pm) · 4 replies
Hello,
I'm having issues with my callback. It calls back a const char*, and the returnbuffer shows during debugging, to be the full value, yet, in torsion, the value shows only as "244".
Code:
what calls the callback:
The implement callback:
Define callback:
So, any idea why it's returning 244? :)
I'm having issues with my callback. It calls back a const char*, and the returnbuffer shows during debugging, to be the full value, yet, in torsion, the value shows only as "244".
Code:
what calls the callback:
// Get the connection of the player (even though we're client side?)
GameConnection* connection = GameConnection::getConnectionToServer();
if (connection)
{
// This stops it from hanging
if (!connection->getCameraObject())
return;
RayInfo ri;
bool hit = false;
disableCollision();
MatrixF mat;
// Get the camera's transform, and output it to the matrix.
connection->getControlCameraTransform(0, &mat);
// Store the camera's position and forward vector.
Point3F startPoint = mat.getPosition();
Point3F endPoint = (mat.getForwardVector() * mDataBlock->pickupRadius) + startPoint;
hit = gServerContainer.castRay(startPoint, endPoint, sInteractionTypeMask, &ri);
char *returnBuffer = Con::getReturnBuffer(256);
dSprintf(returnBuffer, 256, "%g %g %g",
ri.point.x, ri.point.y, ri.point.z);
if (hit)
mDataBlock->onInteractionHit_callback( returnBuffer );
// Leave last.
enableCollision();
}The implement callback:
IMPLEMENT_CALLBACK( PlayerData, onInteractionHit, void, (const char* hitpoint ), ( hitpoint ), "@brief Called when the player hits something interactable.n" "@param hitpoint the point the raycast itn" "@see interactionn" );
Define callback:
DECLARE_CALLBACK( void, onInteractionHit, (const char* hitpoint ));
So, any idea why it's returning 244? :)
#2
function <SomeDataBlock>::onInteractionHit(%this, %hitPoint){...}
That 'hidden' %this param can be tricky. If you forget to include it then the rest of the function params will be incorrect.
12/01/2011 (7:57 pm)
How is the onInteractionHit method defined in TScript? It should be something similar to: function <SomeDataBlock>::onInteractionHit(%this, %hitPoint){...}
That 'hidden' %this param can be tricky. If you forget to include it then the rest of the function params will be incorrect.
#3
12/02/2011 (4:11 am)
Problem solved! it was the rogue %this causing havoc.
#4
12/02/2011 (7:31 am)
I love rogue %this - it's my favorite stumbling block! Good catch Chris! For me it's always easier to spot when it starts spouting object names or classes instead of numbers.
Torque Owner A F
Default Studio Name
Here is how projectile.cpp does it:
IMPLEMENT_CALLBACK( ProjectileData, onCollision, void, ( Projectile* proj, SceneObject* col, F32 fade, Point3F pos, Point3F normal ), ( proj, col, fade, pos, normal ),"@n" );void Projectile::onCollision(const Point3F& hitPosition, const Point3F& hitNormal, SceneObject* hitObject) { ... mDataBlock->onCollision_callback( this, hitObject, mFadeValue, hitPosition, hitNormal );