Game Development Community

Load a new mission?

by CodingChris · in Torque Game Engine · 11/20/2006 (5:55 am) · 19 replies

Hello,
I want ever when my trigger is entered, load a new mission. This is my code
function DefaultTrigger::onEnterTrigger(%this,%trigger,%obj)
{
   // This method is called whenever an object enters the %trigger
   // area, the object is passed as %obj.  The default onEnterTrigger
   // method (in the C++ code) invokes the ::onTrigger(%trigger,1) method on
   // every object (whatever it's type) in the same group as the trigger.
   Parent::onEnterTrigger(%this,%trigger,%obj);
   // Display the loading GUI
Disconnect();
  Canvas.setContent(LoadingGui);
   LOAD_MapName.setText( "Porting" );
  	LOAD_MapDescription.setText( "<font:Arial:16>Please wait while porting ended...");
   Canvas.repaint();

   // Start up the server..
   createServer("SinglePlayer", expandFileName("~/data/missions/2.mis"));
   %conn = new GameConnection(ServerConnection);
   RootGroup.add(ServerConnection);
   %conn.setConnectArgs($pref::Player::Name);
   %conn.setJoinPassword($Client::Password);
   %conn.connectLocal();

}

But When I use this Code Torque destroys.

Could anyone help me?

#1
11/20/2006 (6:15 am)
I dont know if this makes any difference at all but I alway have the line:

Parent::onEnterTrigger(%this,%trigger,%obj);

as the last line in the function.
#2
11/20/2006 (6:19 am)
No difference
#3
11/20/2006 (9:19 am)
I tried this exact same thing recently. And yes, it crashed when I tried to launch a new mission.

For some reason if you try to disconnect and load a new mission inside onEnterTrigger it will crash Torque. The easiest way I found to get around it was to pop up a message box:

function DefaultTrigger::onEnterTrigger(%this,%trigger,%obj)
{

MessageBoxYesNo("Launch Mission?","Do you want to launch a new mission?","launchmission();","");
}

launchmission() would be a function containing all of the code you currently have in your onEnterTrigger function. If the player clicks [YES] then it will launch the mission without crashing.

This may not be exactly what you are looking for but it may get you started or spark some ideas.

-Robert
#4
11/20/2006 (9:43 am)
Now my code is:
function launchmission()
{
 Canvas.setContent(LoadingGui);
   LOAD_MapName.setText( "Porting" );
  	LOAD_MapDescription.setText( "<font:Arial:16>Please wait while porting ended...");
   Canvas.repaint();

   // Start up the server..
   createServer("SinglePlayer", expandFileName("~/data/missions/2.mis"));
   %conn = new GameConnection(ServerConnection);
   RootGroup.add(ServerConnection);
   %conn.setConnectArgs($pref::Player::Name);
   %conn.setJoinPassword($Client::Password);
   %conn.connectLocal();
   Parent::onEnterTrigger(%this,%trigger,%obj);
}
But Torque crashed...
It doesn't help me. Could you post your code here?
#5
11/20/2006 (10:51 am)
I guess you need to use schedule. Read here.
#6
11/20/2006 (12:46 pm)
Messagebox is a cool idea actually, cause they might not want to load a new area, course that depends on your game. Good idea for a mmorpg anyways, maybe not needed for a single player.
#7
11/20/2006 (9:24 pm)
@Christian

I commented out "Parent::onEnterTrigger(%this,%trigger,%obj);" completely.

function DefaultTrigger::onEnterTrigger(%this,%trigger,%obj)
{

   //Parent::onEnterTrigger(%this,%trigger,%obj);
	
  MessageBoxYesNo( "Launch Mission?", "Do You want to launch a new mission?", "SwitchMission();", "");

}


function SwitchMission()
{
        ServerConnection.delete();
        destroyServer();
        clearTextureHolds();
        purgeResources();
	
        createServer("SinglePlayer", "~/data/missions/2.mis" );
        %conn = new GameConnection(ServerConnection);
        %conn.setConnectArgs("PLAYER1");
        
        Canvas.setContent(LoadingGui);
        %conn.connectLocal();
}

This works for me and does not crash. I am doing this in Torque 1.5.
#8
11/21/2006 (5:41 am)
When I use this function the MessageBox appears and then I see the LoadMission-Dialog, there is the text "Waiting for server", but then Torque does nothing, Torque doesn't crash, because the LoadingDialog works fine. There is nothing special in the log. I use Torque 1.4.2
#9
11/21/2006 (7:38 am)
Robert is there anything you doing different in Torque 1.5 because I try this I am get the same as Christian.

Edit for found the problem.

Change this line

createServer("SinglePlayer", "~/data/missions/2.mis" );

to

createServer("SinglePlayer", "starter.fps/data/missions/2.mis" );

I test this with Torque 1.4.2 and 1.5.0 and it work perfectly.
#10
11/21/2006 (8:52 am)
@Fucifer & Christian

Yes, make sure the path to your mission is correct. My code is just an example so you'll probably need to tweak it for your use.

Good luck!

Robert
#11
11/21/2006 (8:59 am)
Now it works.

Thanks
#12
11/21/2006 (9:36 am)
When I get some time I going to try add some code so you can switch to any mission you want with one trigger.
#13
11/21/2006 (9:38 am)
This sounds pretty cool.
#14
01/03/2007 (7:54 am)
I just used it with AFX, and itworks like a charm, i also hooked a trigger to it, so when you step onto the portal you get wisked away :)
#15
01/03/2007 (9:49 am)
Would you like to share that.
#16
01/03/2007 (7:47 pm)
Its as easy as adding the trigger in the first map. Remember that triggers name. youcan reduce the tickperiodMS, thats just a time delay to prevent a instant trigger hit. but that works for me. Thank you for working on this btw.

Datablock TriggerData(nameoftrigger)
{
tickPeriodMS = 100;
};
function nameoftrigger::onEnterTrigger(%this,%trigger,%obj)
{
//Parent::onEnterTrigger(%this,%trigger,%obj);
MessageBoxYesNo( "Launch Mission?", "Do You want to launch a new mission?", "SwitchMission();", "");
}
function SwitchMission()
{
ServerConnection.delete();
destroyServer();
clearTextureHolds();
purgeResources();

createServer("SinglePlayer", "name of directory/data/missions/your.mis" );
%conn = new GameConnection(ServerConnection);
%conn.setConnectArgs("PLAYER1");

Canvas.setContent(LoadingGui);
%conn.connectLocal();}
#17
06/30/2009 (11:42 pm)
Hello there everyone. Can anybody tell me why when I use the load mission trigger in this format, with a messageBox, everything is ok

datablock TriggerData(nameoftrigger) {
tickPeriodMS = 1000;
};

function nameoftrigger::onEnterTrigger(%this,%trigger,%obj)
{
MessageBoxYesNo( "Launch Mission?", "Do You want to launch a new mission?", "SwitchMission();", "");
}
function SwitchMission()
{
ServerConnection.delete();
destroyServer();
clearTextureHolds();
purgeResources();

createServer("SinglePlayer", "starter.racing/data/missions/racing.mis" );
%conn = new GameConnection(ServerConnection);
%conn.setConnectArgs("PLAYER1");

Canvas.setContent(LoadingGui);
%conn.connectLocal();}

function addTrigger(){
%obj = new Trigger() {
position = "100 100 100";
scale = "1 1 1";
rotation = "0 0 1 0";
dataBlock = nameoftrigger;
polyhedron = "0 0 0 1 0 0 0 -1 0 0 0 1";
};
}

but when I'm tring to execute the function SwitchMission(), without using the messageBox, like this :

.
.
.
function nameoftrigger::onEnterTrigger(%this,%trigger,%obj)
{
SwitchMission();
}
.
.
.
Torque crahes down, even if it compiles without any kind of error ?
#18
06/30/2009 (11:51 pm)
by the way the crash occurs when my character tries to enter the trigger. I discovered Torque quite recently, so I'm quite a rookie in all of this, and I don't really understand what could be wrong.
#19
07/04/2009 (1:29 am)
Well I found the problem. The function SwitchMission had to be called with scheudle. So, for the ones interested, the final code for the switch mission trigger without a message box looks like this:

datablock TriggerData(TheTrigger) {
tickPeriodMS = 1000;
};

function TheTrigger::onEnterTrigger(%this,%trigger,%obj)
{
schedule( 0, 0, "SwitchMission" );
}

function SwitchMission()
{
ServerConnection.delete();
destroyServer();
clearTextureHolds();
purgeResources();

createServer("SinglePlayer", "path to your mission/mission.mis" );
%conn = new GameConnection(ServerConnection);
%conn.setConnectArgs("PLAYER1");

Canvas.setContent(LoadingGui);
%conn.connectLocal();}

function addTrigger(){
%obj = new Trigger() {
position = "100 100 100";
scale = "1 1 1";
rotation = "0 0 1 0";
dataBlock = TheTrigger;
polyhedron = "0 0 0 1 0 0 0 -1 0 0 0 1";
};
}

Good luck...hope this helped.