Game Development Community

Levels

by Quentin Headen · in Game Design and Creative Issues · 10/25/2006 (9:16 am) · 20 replies

Hello. I just wanted to know how to load mutiple levels in one game. I am making a racing game and I want to make mutiple tracks. How can I do this.

Thanks

About the author

Just your average programmer who tries to finish the projects he starts. :) I am currently focused on creating games with Torque engines. My website is http://phaseshiftsoftware.com


#1
10/25/2006 (9:38 am)
You might have better luck posting in the Mods Forum under the TGE Engine Public Section. =)

But, in an attempt to answer your question, you want to load multiple levels at once? Or do you want to have one level loaded, and when that is finished, load another?
#2
10/25/2006 (12:25 pm)
I want to load one level, then once I finish it, load another.
#3
10/25/2006 (12:35 pm)
There are lots of different ways you can go about this. Have you looked at the SM_StartMission() function in example\starter.racing\client\ui\startMissionGui.gui?

The process is pretty easy, and you can write your own custom functions following their method.
1. Have the file name of your next level in a variable.
2. Pick a server type (single or multiplayer).
3. call createServer() using your variables
4. Follow the rest of their code in the example

Try that, and let us know how it goes.
#4
10/25/2006 (3:55 pm)
How can I put the level name in a variable? I'm not that good at loading levels.
#5
10/25/2006 (4:45 pm)
Did you check out their script?

%number = 3;             // Storing a number

%word = "Hello";        // Storing a word

%level = "data/missions/myMission.mis";    // Storing a filepath to level
#6
10/25/2006 (9:33 pm)
I don't see the level variable in the startMissionGui.gui. Please show me where this is.
#7
10/26/2006 (5:27 am)
Did you read the SM_StartMission() function? Levels are called missions in Torque. You can find the variable called mission in that function.
#8
10/26/2006 (8:00 am)
I notice though that this code puts the missions in a list. I want to just load one default mission, and then once finished, load another one. How can I do that.
#9
10/26/2006 (8:29 am)
Well, I didn't want to give you the code, but since you are a beginner programmer and I can see you are trying, give this code a shot:

function loadSecondRace()
{
   // Store the mission filepath of [b]YOUR[/b] mission in a variable
   %mission = "Starter.racing/data/missions/secondMission.mis";

   // Make the level multiplayer ("%serverType = "SinglePlayer";" would make it singleplayer)
   %serverType = "MultiPlayer";
   
   // Create the server and connect to it
   createServer(%serverType, %mission);
   %conn = new GameConnection(ServerConnection);
   RootGroup.add(ServerConnection);
   %conn.setConnectArgs($pref::Player::Name);
   %conn.setJoinPassword($Client::Password);
   %conn.connectLocal();
}

The easiest way to test this is to copy the function into one of your scripts, and then load your first mission. During the first mission, open the Console (~), and type loadSecondRace(). Provided you copied the function correctly and both missions are valid, your first mission will end and your second mission will load up.

As a learning procedure, compare this function to SM_StartMission(). They are practically the same, except I just removed the list portion and hardcoded the mission path.

A programmers Mantra:
Quote: Read. Read Code. Code
#10
10/26/2006 (8:35 am)
Later on, after you've gotten more familiar with using Torque Script, you can look into implementing the function cycleGame(). This is where you'd set up an automated process for changing levels, but it probably requires more coding than you might be used to ATM. You can find this function in example\starter.racing\server\scripts\game.cs.
#11
10/26/2006 (10:15 am)
Sorry to ba a pest, but I am trying to do this but it won't work. Mabe my mission isn't valid.
#12
10/26/2006 (10:19 am)
Maybe, what filepath are you using to load your second mission?
#13
10/26/2006 (11:04 am)
This is my code:


function level()
{

//The mission I am using is simply called Mymission
%mission = "SDK\example\demo\data\missions\Mymission.mis";


%servertype = "Multiplayer";


// Create the server and connect to it
createServer(%serverType, %mission);
%conn = new GameConnection(ServerConnection);
RootGroup.add(ServerConnection);
%conn.setConnectArgs($pref::Player::Name);
%conn.setJoinPassword($Client::Password);
%conn.connectLocal();
}






When I type in level(), the game window just diapears. Then I have to start the game again.
#14
10/26/2006 (12:19 pm)
First,

Change:
%mission = "SDK\example\demo\data\missions\Mymission.mis";

To

%mission = "./demo/data/missions/Mymission.mis";

Second,

Where and when are you calling this function? During another mission? From the MainMenu?
#15
10/26/2006 (12:34 pm)
I am calling this mission during the default mission. I changed the directory path, but the game still cuts off.
#16
10/26/2006 (2:26 pm)
I just modified the script so that the game will load my level loading script at the main menu. I typed in loadSecondRace() and the loading screen came up, but it won't load. The progress bar just stands still. I am horrible at this.
#17
10/26/2006 (2:31 pm)
Don't get discouraged. It's tough learning a new language, and you are trying to learn an entire engine. You're learning, and that's progress. You've got the load screen up, so you are almost there. Copy and paste your modified code and function, exactly how you have it, in the script in your next post so I can have a look at it.
#18
10/26/2006 (2:36 pm)
Yahooooooooooooooo!!! I finally got it. The level loaded up with no problem. Why the loading screen came up, but there was no progress was because I had a wrong directory.




Here is the code. By the way, I changed the mission name from Mymission to qlevel.



function loadSecondRace()
{

//The mission I am using is simply called qlevel
%mission = "starter.fps/data/missions/qlevel.mis";


%servertype = "Multiplayer";


// Create the server and connect to it
createServer(%serverType, %mission);
%conn = new GameConnection(ServerConnection);
RootGroup.add(ServerConnection);
%conn.setConnectArgs($pref::Player::Name);
%conn.setJoinPassword($Client::Password);
%conn.connectLocal();
}




Michael, I want to thank you for sticking with me and helping me. That is the type of help that I like. Thanks again.

If I have another problem, I will let you know.
#19
10/26/2006 (2:42 pm)
Awesome! Congrats man! This is why it's called Garage Games Community! I was in the same place when I first started using TGE a few years back, lost in the script asking for help (thanks Zepp).

Just as a suggestion, if you have any other script questions or problems, post here:
Mods Forum

You'll be able to get feedback from others since that's a more watched forum. Keep at it. Definitely look forward to seeing what you'll produce.
#20
10/26/2006 (2:49 pm)
Cheers!