AIPlayer.delete() crashing game
by Harley · in Torque Game Engine · 06/20/2005 (3:03 am) · 6 replies
I am trying to delete an AIPlayer when it enters a trigger but it is crashing my game. The AIPlayer gets to the trigger by following a path node which I have placed inside the trigger. I read a thread somewhere on this site where someone else was having similar problems and it was suggested that he try %bot.done(). However this function doesn't appear to exist? The strange thing is that when I try to use 1234.delete(); in the console it doesn't crash? Any suggestions? Below is the code I am using...
I'm not sure if it helps at all but the AIPlayers are spawned every 4 seconds using the schedule command:
Thanks,
Harley.
function DeleteBotTrigger::onEnterTrigger(%this, %trigger, %obj)
{
echo("%this.getName(): " @ %this.getName());
echo("%trigger.getName(): " @ %trigger.getName());
echo("%obj.getid(): " @ %obj.getid());
%obj.delete();
}I'm not sure if it helps at all but the AIPlayers are spawned every 4 seconds using the schedule command:
function AIManager::Think(%this)
{
//echo("AIManager.Think()");
SpawnBot();
%this.schedule(4000, Think); //Call this function every 4 seconds
}Thanks,
Harley.
#2
I went one step further than dump() and did a search in the engine code ;-). Unfortunately (at least in the version I have, v1.3) kill() doesn't exist.
But yes I have had some problems with this object and I appreciate the suggestions (in this thread and the other).
06/21/2005 (3:28 am)
Seeing if I am dealing with the sort of object I am dealing with? I am pretty sure it is?! I want bots (well objects that I could use as bots/objects that are easy to give some sort of AI behaviour to). I have this object doing everything I want (moving to nodes, following player if I want it etc etc), I just cant delete() it. Also, this is the object type that is taught to be used in tutorials, so if there is some other object that I should be using I'm all up for suggestions. I am using my own mesh however so I will try it with the player.dts that comes with the sdk to see if I have the same problem. I went one step further than dump() and did a search in the engine code ;-). Unfortunately (at least in the version I have, v1.3) kill() doesn't exist.
But yes I have had some problems with this object and I appreciate the suggestions (in this thread and the other).
#3
By scheduling the delete with zero it will wait to execute it until the next frame when it is not being actively used by the engine. Let me know if this works for you.
06/21/2005 (3:58 pm)
@Harley - I think your problem is that the AIPlayer is still in use by the engine (it's on the stack) when you delete it in DeleteBotTrigger::onEnterTrigger(). So when your code returns and it tries to access the AIPlayer it is gone and hence crashes. Insted try this:function DeleteBotTrigger::onEnterTrigger(%this, %trigger, %obj)
{
echo("%this.getName(): " @ %this.getName());
echo("%trigger.getName(): " @ %trigger.getName());
echo("%obj.getid(): " @ %obj.getid());
%obj.schedule( 0, delete );
}By scheduling the delete with zero it will wait to execute it until the next frame when it is not being actively used by the engine. Let me know if this works for you.
#4
Harley.
06/22/2005 (5:00 am)
@ Tom - You legend! In that thread I mentioned earlier someone said something about this and I thought i tried that but I am guessing I guffed up the syntax or used the wrong object or something. So then I tried using %obj.stop() before I tried deleting it but still no luck. However when I tried doing what you suggested it worked perfectly. I have tried so many little hacks but with no luck. Thanks heaps, I can finally move on!Harley.
#5
06/22/2005 (5:33 am)
Glad i could help!
Torque Owner Mark Storer
"You keep using that object. I do not think it does what you think it does." --Innego "Hackmeister" Montoya