Game Development Community

Level Specific Script - TGE/A

by Steve Acaster · in Torque Game Engine · 02/22/2010 (8:24 pm) · 0 replies

Should be fine for both TGE and TGEA - originally done for T3D, so apologies if I've missed anything TGE specific (though I think I've retro-fitted it okay), it's not real complex so you should be able to see how it all works (and if you come up with a better solution - post it!).

1. Take all of your level specific data (triggers, etc) and place it in a *.cs file with the same name as your mission file. (eg: mylevel.mis = mylevel.cs)

2. Create a folder called "levels" in scripts/server. (eg:scripts/server/levels)

Place mylevel.cs into this new folder and rename mylevel.cs to mylevel.mis (but keep it a cs file, eg: in the directory it's Name= "mylevel.mis" and the Type= "CS File". Don't add an extra ".cs" or you'll have "mylevel.mis.cs" as the name, and that's really "mylevel.mis.cs.cs" and that ain't right (using a Win7 directory structure -- you'll soon know if it's all gone wrong anyhow!)).

3. Create a file called "loadlevels.cs" and slap this scriptette in it.
function loadleveldata()
{
echo("LOAD LEVEL SPECIFIC DATA - " @ "./" @ $Server::MissionFile @ ".cs");
		exec("./" @ $Server::MissionFile @ ".cs");
}
Remember to exec it from game.cs "onServerCreated" (if I remember TGE properly).

4. Fire this function off when the level loads up - NOT afterwards or you're trigger data won't get loaded into memory when the trigger objects look for it. In server/scripts/game.cs you'll probably want to stick this in "onServerCreated" (though you could risk OnClientEnterGame and see if it works) - any later and it might not hook the triggers to their data:
LoadLevelData();//yorks - load the level specific data

5. And when you load a level, in the console it should echo:
"LOAD LEVEL SPECIFIC DATA - ./levels/mylevel.mis.cs".
If there is no specific level file you will get a cyan message saying it can't find the script.

Just to note, if you want events to "kick-off" at the start (like stuff to spawn immediately etc), you should make a function in your mylevel.mis.cs ... let's call it function LevelDataStart().
function LevelDataStart()
{
//Science! Kicking arse since the Stone Age
echo("LevelData Functions Startup");
}

Fire this off from the end of game.cs/onMissionLoaded() (You could also try this in "Startgame" - or "OnClientEnterGame") - any sooner and it'll missfire and stuff (like Ai won't spawn).

LevelDataStart();//yorks startup level functions
}


And that *should* be that. Currently no way to delete the original datablocks once loaded into memory. So rather than loading everything at once, it loads it a mission at a time.