Game Development Community

SimGroup::OnObjectAdded

by Dreamer · in Torque Game Engine · 10/05/2006 (11:39 pm) · 0 replies

I have need of a script callback each time an object is added to a SimGroup.
This looks like it should work, but it doesn't appear to ever get called.
Can someone please help me figure out where I'm going wrong?

In simbase.cc
void SimGroup::addObject(SimObject* obj)
{
   lock();

   // Make sure we aren't adding ourself.  This isn't the most robust check
   // but it should be good enough to prevent some self-foot-shooting.
   if(obj == this)
   {
      Con::errorf("SimGroup::addObject - (%d) can't add self!", getIdString());
      unlock();
      return;
   }

   if (obj->mGroup != this) 
   {
      if (obj->mGroup)
         obj->mGroup->removeObject(obj);
      nameDictionary.insert(obj);
      obj->mGroup = this;
      objectList.push_back(obj); // force it into the object list
                                 // doesn't get a delete notify
      obj->onGroupAdd();
      [b]Con::executef(this, 2, "onObjectAdded",obj->getIdString());[/b]
      
   }
   unlock();
}

And in client/scripts/inventory.cs
if(!isObject(Inventory)){
   new SimGroup(Inventory);
}
Inventory.add(%item);

function Inventory::onObjectAdded(%this,%obj){
    echo(%obj SPC "was added to inventory!");
}

Any ideas on what I could be doing wrong here?