Game Development Community

OnAdd/OnNewDataBlock Calls not working

by William Harding · in Torque Game Engine Advanced · 04/10/2006 (2:31 am) · 0 replies

First off I have the latest head version...

I've been working with starter.fps for a couple days now and discovered something really weird I can't figure out. It looks to me like an engine bug, frankly.

So I added a health kit to the mission (HealthKit).

And wanted to make a function so it would do something on init...

function HealthKit::onNewDataBlock(%this,%user)
{
echo("Health kit data block added.");
if (%user.client)
{
%user.client.player.setExternalRenderFocus(%this);
}
}

All very well and good, but it's never called. My echo never comes up...

But here's the rub. It -works- if I populate the C code with echo messages!

They're commented out here, but you can see two of them that I added in... (GameBase is a parent of Item.)

void GameBase::scriptOnNewDataBlock()
{
//Con::printf("Script New Data Block");
// Script onNewDataBlock() must be called by the leaf class
// after everything is loaded.
if (!isGhost())
{
//Con::printf("Script New Data Block 2");
Con::executef(mDataBlock,2,"onNewDataBlock",scriptThis());
}
}

I have added comments to the execute function this is tied to...

const char *execute(SimObject *object, S32 argc, const char *argv[])
{
Con::printf("Execute");
static char idBuf[16];
if(argc < 2)
return "";
if(object->getNamespace())
{
dSprintf(idBuf, sizeof(idBuf), "%d", object->getId());
argv[1] = idBuf;

StringTableEntry funcName = StringTable->insert(argv[0]);
Namespace::Entry *ent = object->getNamespace()->lookup(funcName);

Con::printf("Script function call %s:%s",object->getName(),funcName);

----

As I discovered, it attempts to call script functions through this gateway above.

If I put in enough echo messages then it will call the script properly! Argh! I'm ready to throw in the towel, call the console messaging an unreliable, broken system, and find some other way of doing what I want.

So what gives? Does populating the console give it enough 'lag time' to be able to run the function? Am I going insane? Is there a better way to call back script functions or know when something is being initialized and call some init code?

Please note the object was placed in the mission in at the base level. (Not in an object subgroup.) So it spawns automatically and I can see it spinning in the level right next to my spawn point. Mostly to taunt me.