Game Development Community

AIPlayer %obj.delete(); crashing torque

by Eros Carvalho · in Torque Game Engine · 04/18/2005 (1:33 pm) · 6 replies

Hi, Im trying to delete some AIPlayer objects that are dynamic created but the torque is crashing...
I need to delete any AIPlayer at any moment of the mission...

btw, if I try to delete any aiplayer with the mission editor it works fine.

#1
04/18/2005 (2:15 pm)
This tends to happen if the AI is not quite finished doing whatever business it needs to do.

Show the code for creation and deletion, maybe I can help here.
#2
04/18/2005 (2:27 pm)
In creation and deletion has nothing special..

creation:

function CreateSoldier(%spawnPoint)
{
    // Create the player object
    %obj= new AiPlayer()
    {
        dataBlock = Soldier;
    };
    %obj.setTransform(%spawnPoint);

    %obj.oIsStopped       =   true;
    %obj.teleport        =   true;
    %obj.stop            = true;
    %obj.isFly           =   false;

    schedule($Game::Player::TimeUpdateSoldier, 0, "SoldierUpdate", %obj);

    MissionCleanup.add(%obj);
}


and deletion is when the AIPlayer hits the trigger:

%obj.InstaKill = true;
%obj.delete();  // this line crashes


the InstaKill thing is a try to wait the AIPlayer stop moving, so it can be deleted (so need comment the .delete() line from trigger).

I think that this crash is because AIPlayer is moving when he enters the trigger but doesnt got his final destination that is trigger position (left-front point of the trigger)

and in the SoldierUpdate i have:

if (%obj.InstaKill)
        %obj.delete();
    else
        schedule($Game::Player::TimeUpdateSoldier, 0, "SoldierUpdate", %obj);

but dont work too.. :(
#3
04/18/2005 (3:01 pm)
Now I have sure that the problem is to use delete when aiplayer is moving..

I have to change some things here to have certain that the aiplayer stopped moving... maybe when changing anim state or other way..
#4
04/18/2005 (3:03 pm)
It may be as simple as scheduling the object for deletion, instead of deleting it immediately. That should allow the simulation time to finish with the object before you snap it out from underneath everyone's feet. If this works, it should work with like a 1 millisecond schedule...2 tops (if the sim isn't done with the object in a single tick or two, it isn't going to be done with it any more than that).

You may also want to try safeDelete, although I'm honestly not sure if that is a T2D only thing, or TAP in general!
#5
04/18/2005 (3:36 pm)
Would
function AIPlayer::done(%this,%time)
{
   %this.schedule(0,"delete");
}
work??

Very curious; cause I'm doing some AI now, and I'm having a bit getting the bots to enter the game as a connection/client to be included on the ScoreBoard and messaging....I wonder why they[bots/ai] in the default setting are not using the AIClient and AIConnection classes? Wouldn't including some of this functionality in these two classes do exactly that; consider each bot as player without a dedicated client control? I'm just beginning to look 'under the hood' and am trying to apply what I see against what the default supplied...
#6
05/15/2007 (10:18 am)
(bringing the post from the death :P, but for a good reason... I think)

I had the same problem, and using 'schedule(1,"delete");' solve it (just in case someone has the same problem in the future)