Game Development Community

LoadMission Problem duging playing game

by Enel · in Torque 3D Professional · 04/19/2010 (1:59 am) · 7 replies

datablock TriggerData(DungeonIn)
{
   // The period is value is used to control how often the console
   // onTriggerTick callback is called while there are any objects
   // in the trigger.  The default value is 100 MS.
   tickPeriodMS = 500;
   
};

function DungeonIn::onEnterTrigger(%this,%trigger,%obj)
{
   schedule( 0, 0, loadMission, "levels/dungeon.mis",false);  
}

i have write this. but Torque has crashed.. and leave this console log


*** LOADING MISSION: levels/dungeon.mis
*** Stage 1 load
*** Stage 2 load
game/c4 -> activatePackages
*** Mission loaded
*** Sending mission load to client: levels/dungeon.mis


i think this problem is mission memory problem.

Trigger is removed by endMission(); but trigger try to check enteringObject it is crashed!..


anyone solve this problem? i cant do this..

#1
04/19/2010 (9:11 am)
I tried to do debug your problem, and it seems like you can't have a loadMission function in a trigger's onEnterTrigger callback (Why? I dunno). This means that you'll have to put the loadMission function in the trigger's onLeaveTrigger function instead (maybe onTickTrigger will work too. Didn't try that)

More specific, this piece of code will work:
function DungeonIn::onLeaveTrigger(%this,%trigger,%obj)
{
   loadMission("levels/dungeon.mis", false);
}
#2
04/19/2010 (9:18 am)
@Marcus L

Thx Marcus.

but your code sometimes dosent work :(

i think should be make Trigger just check EnterTrigger :P

why this problem has break out, playerList leave in Trigger when Try to load nextMission..


anybody another idea?
#3
04/19/2010 (11:56 am)
Tried and tested in 1.1b1.

function yourTrigger::onEnterTrigger(%this,%trigger,%obj)
{
%checkclass = %obj.getclassname();
   if(%checkclass $= "player")
	{
			schedule(500, 0, "loadNewLevel");

	}
	else
	{
echo("NOT player in trigger - do nothing");
	}
   Parent::onEnterTrigger(%this,%trigger,%obj);
}

function loadNewLevel()
{
loadMission("levels/yourlevel.mis");
echo("loadNewLevel Function activated!");
}

Just calling the function without the schedule produces a crash.
#4
04/20/2010 (1:59 am)
@Steve

No it isnt schedule produces a crash.

it is Trigger's crash try to cheak list in triggerObject or PlayerObject try to check in collision with trigger
#5
04/20/2010 (5:41 am)
Which is why you should give it time for the Trigger to check what the Object inside is.
#6
04/20/2010 (7:03 am)
PlayerObject do try to move next map.
#7
06/05/2010 (4:04 am)
I was having problems as well. Even adding a 5000 delay in the schedule call was causing the mission load to crash. What I found works is to combine the advice of Marcus and Steve. That is, add Steve's code to the OnLeaveTrigger event instead of OnEnterTrigger. As far as I can tell Torque is re-firing the OnEnter event because the player is still inside the trigger and crashing. You could probably disable the trigger in the OnEnterTrigger event and let the schedule do the load (that should work) but seems much easier to just use the OnLeaveTrigger event. That's working for me at least...