Game Development Community

Load Mission function

by Richard Jones · in Torque Game Engine · 02/22/2002 (1:35 pm) · 11 replies

Hello,

I'm fairly new to Torque and I'm trying to write a function that will load up a mission (called "Chapter 1") instead of selecting one from the list. Being a single player game, the mission loaded will always be the same when starting a new game, so there is no need for the user to actually select a mission.
I call the function StartMission by clicking on a button on the Main Menu and this brings up the Loading GUI. However, the mission name and description is not shown and the mission fails to load (I have to press the cancel button to get back to the main menu). Could someone please tell me what's wrong with the code below? The script is obviously not loading the mission properly and I suspect that it maybe a problem with the %mission variable. I have tried specifing the full filename, but this doesn't seem to work either. The mission loads fine when I try and load it the normal way. Anyway, here's the code...

function StartMission()
{
%mission = "Chapter 1";
%serverType = "SinglePlayer";

createServer(%serverType, %mission);
localConnect($pref::Player::Name);
}

...Any ideas?

Thanks

#1
02/22/2002 (4:04 pm)
%mission should include the relevant paths
:)
#2
02/22/2002 (4:49 pm)
You mean state the full file path?
I've tried:

%mission = "c:\torque\example\rocketman\data\missions\training\chapter 1.mis";

%mission = "./data/missions/training/chapter 1.mis";

%mission = "c:/torque/example/rocketman/data/missions/training/chapter 1.mis";

None of these seem to work and the file is definately there :(
#3
02/22/2002 (4:57 pm)
Try the path that would start with 'fps/'
#4
02/22/2002 (5:10 pm)
The project I'm working on is effectively a mod of the sample project "fps" called "rocketman". Effectively "rocketman" is the "fps" directory for this project (it started out as an exact copy). As I say, I can load the mission OK via a list box control as in the sample code, so I know the file is OK and the location of the file is valid.
#5
06/22/2002 (5:14 pm)
Did you get this working Richard?
#6
07/22/2002 (6:03 am)
Please keep in mind whenever you use a '\' within quotes, you must use another '\'. Reason being is that '\'servers as a delimeter to special functions. For example, \n is new line, \t is tab, etc. If you do something like this "C:\Torque", the compiler looks for the command \T which is not what you want to do. You want it to look like this "C:\\Torque". Fortunately you can think of '/' = "\\", so "C:/Torque" is legit as well.
#7
07/24/2002 (4:09 pm)
I think it works with this script, but then my game crashed:

%file = findFirstFile("*/waterworld.mis");
loadMission( %file, true ) ;
localConnect($pref::Player::Name);
#8
06/05/2003 (9:10 am)
Did you guys get this to work? I'm trying to figure it out too. I want to make a button that starts a certain mission. So far, its not working out for me too well.
#9
06/06/2003 (1:03 pm)
Ok, try this
function StartNewGame()
{
CreateServer("SinglePlayer",$userMods @ "/data/missions/scorchedPlanet.mis");
%conn = new GameConnection(ServerConnection);
RootGroup.add(ServerConnection);
%conn.setConnectArgs($pref::Player::Name);
%conn.setJoinPassword($Client::Password);
%conn.connectLocal();

}
Note, this is for the head version, for 1.12
function StartNewGame()
{
CreateServer("SinglePlayer",$userMods @ "/data/missions/scorchedPlanet.mis");
localConnect($pref::Player::Name);
}
but I'm not sure
Davide
P.S. obviously : create a button that call this function
#10
04/04/2007 (7:44 am)
How bout loading a new mission instead of creating a new server???
#11
04/04/2007 (8:06 am)
Go to this link and download the single player kit. Open starter.fps\client\init.cs. Look at this
function loadSinglePlayer(), this is the function you need for single player game. Create a button for mainMenuGui.cs (\client\ui). Enter this " Canvas.setContent(startMissionGui);"; " in the command field. you should be good to go.

www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6040