Game Development Community

Con::execute - 0 has no namespace: onAnimationStart

by Michael Woerister · in Torque Game Builder · 05/20/2006 (4:25 am) · 7 replies

Hi,
this warning whenever a t2dAnimatedSprite is created has been in there since ages and it is kind of annoying.

The fix (in t2dAnimatedSprite::playAnimation):
// Play Animation; okay?
    if ( mAnimationController.playAnimation( animationName, autoRestore, frameIndex, mergeTime ) )
    {
        // Yes, so do script callback.
        [b]if( isProperlyAdded() )[/b]
            Con::executef( this, 1, "onAnimationStart" );
        // Return Okay.
        return true;
    }

This check should prevent the callback from being called before the object is registered in the Sim.

-Michael

#1
05/20/2006 (6:48 am)
The 1 in Con::executef() should be 2.
#2
05/20/2006 (7:28 am)
Quote:
The 1 in Con::executef() should be 2.

Why?
#3
05/20/2006 (8:42 am)
Because the object form of Con::executef() automatically adds the %this var but it doesnt automatically modify argc. Thus, argc needs to be 2 (1 for the function name and 1 for %this).

T.
#4
05/20/2006 (8:46 am)
If I don't overlook something here, it indeed does modify argc:
const char *executef(SimObject *object, S32 argc, ...)
{
   const char *argv[128];

   va_list args;
   va_start(args, argc);
   for(S32 i = 0; i < argc; i++)
      argv[i+1] = va_arg(args, const char *);
   va_end(args);
   argv[0] = argv[1];
   [b]argc++;[/b]

   return execute(object, argc, argv);
}
#5
05/20/2006 (11:06 am)
Hmm. Guess I must have missed that.

T.
#6
05/23/2006 (12:52 pm)
Michael,
Good catch, though your check would be more properly served with an isMethod( "onAnimationStart" ) call. isMethod is provided to check for a proper namespace before attempting an executef to avoid unnecessary console executions and console warnings. It should look like the below.

// Play Animation; okay?
    if ( mAnimationController.playAnimation( animationName, autoRestore, frameIndex, mergeTime ) )
    {
        // Yes, so do script callback.
        if( [b]isMethod( "onAnimationStart" )[/b] )
            Con::executef( this, 1, "onAnimationStart" );
        // Return Okay.
        return true;
    }

This has been fixed as of today in our internal repo, as well as the resulting find of onFrameChange not properly checking it's method before execution as well in the same file.

Cheers,
-Justin
#7
05/23/2006 (1:09 pm)
Yes, that's better indeed.