executef calling function twice, or is it?
by Justin Mosiman · in Torque Game Builder · 02/12/2009 (8:39 pm) · 0 replies
Hello,
I've found a strange problem, and I have no idea why it is happening. In my game, two units attack each other. As soon as the units are done attacking, they report this to the object manager so it knows the current state of all objects. Initially, the TorqueScript function objectDoneAttacking() is called, which calls the two object managers (one for each player, engine side):
Within the engine, I have:
Finally the script takes over again with startMoving:
The code functions as expected, but for some reason startMoving is being called twice. From the log:
In this case, the FP (first player)'s object defeated the second, so that's why there is nothing under the SP objectDoneAttacking.
I've stepped through this code C++ side, and ObjectManager::objectDoneAttacking() only gets called once, but startMoving outputs that it got called twice. How could this happen? The engine side of the log shows that it is only be run once, but the torque script is being run twice.
Any help is greatly appreciated, it's a mystery to me...
Justin
I've found a strange problem, and I have no idea why it is happening. In my game, two units attack each other. As soon as the units are done attacking, they report this to the object manager so it knows the current state of all objects. Initially, the TorqueScript function objectDoneAttacking() is called, which calls the two object managers (one for each player, engine side):
function objectDoneAttacking(){
echo("objectDoneAttacking FP");
$FPObjectManager.objectDoneAttacking();
%FPObj = $FPObjectManager.checkSpawnStatus();
if(isObject(%FPObj)){
%FPObj.spawnFinished();
}
echo("objectDoneAttacking SP");
$SPObjectManager.objectDoneAttacking();
%SPObj = $SPObjectManager.checkSpawnStatus();
if(isObject(%SPObj)){
%SPObj.spawnFinished();
}
}Within the engine, I have:
void ObjectManager::objectDoneAttacking(){
Con::errorf("ObjectManager::objectDoneAttacking()");
mIsAttacking = false;
mAllUnitsStopped = false;
if(mActiveUnits.size() == 0)
return;
// First we need to see if mActiveUnits[mActiveUnits.size()-1] is still alive.
if(dStrcmp(Con::executef(Sim::findObject(mActiveUnits[mActiveUnits.size()-1]->getObj()->getId()),1,"isAlive"),"0")==0){
// We died, remove from the active list
Con::errorf("mActiveUnits: remove %d, size: %d",mActiveUnits[mActiveUnits.size()-1]->getObj()->getId(), mActiveUnits.size()-1);
mActiveUnits.pop_back();
}
for(int i=0;i<mActiveUnits.size();++i){
// We start at once
Con::errorf("ObjectManager::objectDoneAttacking(): %d", mActiveUnits[i]->getObj()->getId());
Con::executef(Sim::findObject(mActiveUnits[i]->getObj()->getId()),1,"startMoving");
}
}Finally the script takes over again with startMoving:
function Dragon::startMoving(%this){
if(%this.isAlive() == false)
return;
echo(%this.getId()," starts moving");
%this.setLinearVelocityX(%this.unitBehavior.moveSpeed);
%this.animationManager.setState("run");
}The code functions as expected, but for some reason startMoving is being called twice. From the log:
Quote:
objectDoneAttacking FP
ObjectManager::objectDoneAttacking()
ObjectManager::objectDoneAttacking(): 1356
1356 starts moving
1356 starts moving
objectDoneAttacking SP
ObjectManager::objectDoneAttacking()
mActiveUnits: remove 1348, size: 0
In this case, the FP (first player)'s object defeated the second, so that's why there is nothing under the SP objectDoneAttacking.
I've stepped through this code C++ side, and ObjectManager::objectDoneAttacking() only gets called once, but startMoving outputs that it got called twice. How could this happen? The engine side of the log shows that it is only be run once, but the torque script is being run twice.
Any help is greatly appreciated, it's a mystery to me...
Justin