Hi. I have the following Angelscript code:
class ElectricLightSource
{
void Interact(User @ user)
{
if (mOwner.GetObject().mState > 0)
{
gObjects.RemovePowerDraw(PowerFunction(this.UpdatePower));
mOwner.GetObject().mState = 0;
}
else
{
gObjects.AddPowerDraw(PowerFunction(this.UpdatePower));
mOwner.GetObject().mState = 2; // Start with power off;
}
}
}
And the C++ functions called are:
...
r = scriptEngine->RegisterFuncdef("void PowerFunction()"); assert( r >= 0 );
r = scriptEngine->RegisterObjectMethod("ObjectManager", "void AddPowerDraw(PowerFunction@)", asMETHOD(ObjectManager,AddPowerDraw), asCALL_THISCALL); assert( r >= 0 );
r = scriptEngine->RegisterObjectMethod("ObjectManager", "void RemovePowerDraw(PowerFunction@)", asMETHOD(ObjectManager,RemovePowerDraw), asCALL_THISCALL); assert( r >= 0 );
...
std::vector<asIScriptFunction*> mPowerCallbacks;
...
void ObjectManager::AddPowerDraw(asIScriptFunction* function)
{
mPowerCallbacks.push_back(function);
}
void ObjectManager::RemovePowerDraw(asIScriptFunction* function)
{
std::vector<asIScriptFunction*>::iterator cur = mPowerCallbacks.begin(), end = mPowerCallbacks.end();
for (; cur != end; cur++)
{
if (*cur == function)
{
--end;
if (cur != end)
*cur = *end;
mPowerCallbacks.pop_back();
return;
}
}
}
My problem is that the remove call, "if (*cur == function)" never passes. What am I doing wrong?