Behavior Callbacks break function arguments for owner, Fix Inside
by Devin Horsman · in Torque Game Builder · 11/04/2009 (12:08 pm) · 0 replies
Some have you may have noticed that when using behaviors and classes with the same object, the %this that gets passed into the owner's version of the callback is not the right object, but in fact the first argument to the last function that was called in the callback of on of the behaviors:
Example:
anObject is a SceneObject with class "TestScript" and both of the above behaviors
Output:
(behavior1 instanceid) is the %this object in TestBehavior1 // as expected
(behavior2 instanceid) is the %this object in TestBehavior2 // as expected
blah2 is the %this object in owner
Tracking down this bug was a major pain. A fix for it is:
in enginesourceconsolecompiledEval.cc after the text (around line 1366)
insert
Example:
//
function TestBehavior::aFunction(%this){
echo(%this SPC "is the %this object in TestBehavior");
echo("blah");
}//
function TestBehavior2::aFunction(%this){
echo(%this SPC "is the %this object in TestBehavior2");
echo("blah2");
}//
function TestScript::aFunction(%this){
echo(%this SPC "is the %this object in owner");
}anObject is a SceneObject with class "TestScript" and both of the above behaviors
anObject.aFunction();
Output:
(behavior1 instanceid) is the %this object in TestBehavior1 // as expected
(behavior2 instanceid) is the %this object in TestBehavior2 // as expected
blah2 is the %this object in owner
Tracking down this bug was a major pain. A fix for it is:
in enginesourceconsolecompiledEval.cc after the text (around line 1366)
bool handlesMethod = gEvalState.thisObject->handlesConsoleMethod(fnName,&routingId);
if( handlesMethod && routingId == MethodOnComponent )
{
DynamicConsoleMethodComponent *pComponent = dynamic_cast<DynamicConsoleMethodComponent*>( gEvalState.thisObject );
if( pComponent )
pComponent->callMethodArgList( callArgc, callArgv, false );
}insert
// Restore argv list STR.getArgcArgv(fnName, &callArgc, &callArgv);
About the author
Game developer from Halifax Nova Scotia.