Game Development Community

Loading levels

by Mirko Topalski · in Torque Game Builder · 11/02/2006 (12:54 pm) · 29 replies

How do i actually load new levels, and how does it work?
Do i write new *.cs files for new levels?
Can you give me some sample code?
I couldnt find anyone anywhere explaining that.

I know there is a loadLevel() function, but when i type just that, nothing happens. Does the name of level file hav eto bi with full path, or just the file name, or i have to reference it relativelly with ..\ and .\
If so, from where do i start, what is the start folder?
Page «Previous 1 2
#1
11/03/2006 (12:52 pm)
Nobody can tell me?
#2
11/03/2006 (1:16 pm)
Look at the code in game.cs - it's called by the levelbuilder and loads a level. Also, look in your documentation for the different level functions. The files you save from the levelbuilder are seperate levels.
#3
11/04/2006 (2:45 am)
I noticed all that, but i still cant load any new levels.

Can anyone give me some sample script?
#5
11/04/2006 (10:35 am)
I have the documentation, but they are not explaining anything there

i tried:
loadLevel("level 2.t2d")
loadLevel("level 2.t2d.dso")
loadLevel( "allCombinationsOfThePath\level 2.t2d" )
sceneWindow2D.loadLevel(allThoseCombinations);
i even tried to call again the gameStart(allThoseCombinations) function

what am i doing wrong?
#6
11/04/2006 (11:05 am)
sceneWindow2D.loadLevel( "~/data/levels/insertyourlevelnamehere.t2d" );

This is assuming that the sceneWindow that you want the level loaded into is sceneWindow2D. This is the default so if you haven't changed it this will work.
#7
11/04/2006 (12:37 pm)
Thnx man, thats all i neaded

no, i havent changed scenewindow name, but when i write that script, the game collapses(??)
#8
11/04/2006 (1:22 pm)
The only thing that I can think of is that you're forgetting to unload the current level. Perhaps that's it?
#9
11/05/2006 (12:19 am)
Hmmm... TGB is still crashing. I am trying to call it now from endGame() func.

...
endGame( "~/data/levels/level 2.t2d" );
...

function endGame( %level )
{
sceneWindow2D.endLevel();
moveMap.pop();

if( isFile( %level ) || isFile( %level @ ".dso"))
sceneWindow2D.loadLevel( %level );
}
#10
11/05/2006 (4:14 pm)
Anyone? can you tell me what am i doing wrong? Please! I cant work further without this.

Please ...
#11
11/06/2006 (4:50 am)
Maybe this link can help you
http://garagegames.com/mg/forums/result.thread.php?qt=53079
#12
11/06/2006 (2:09 pm)
Thanx for interesting in my problem.

The game is still crashing. In fact it is crashing even without trying to load level, just by calling endLevel() function.

Yea, it seams that the problem is in not-recognising the filename. Even when i write those stuff from that link you gave me. Ill have to experiment more with that. I still dont have the solution. Thnx anyway.
#13
11/07/2006 (3:07 am)
Maybe u can give us your troubled script
#14
11/09/2006 (12:07 am)
Instead of
sceneWindow2D.loadLevel( "~/data/levels/insertyourlevelnamehere.t2d" );

do
sceneWindow2D.loadLevel( "YourProjectFolder/data/levels/insertyourlevelnamehere.t2d" );
#15
11/09/2006 (7:52 am)
I tried, all that.
Look, in empty project i type only:

function sceneWindow2d::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{
if( isFile( "~/data/levels/level2.t2d" ) || isFile( "~/data/levels/level2.t2d" @ ".dso"))
echo("file is ok");
sceneWindow2D.loadLevel( "~/data/levels/level2.t2d" );
}

end cosole output is (on mouse click):
file is ok
error loading level ~/data/levels/level2.t2d. Invalid file

but all objects dessapear from screen. (???) Whatever combination i make, its not working. do i have to attach/detach something at scenewindow/scengraph? (whatever they are) :)
#16
11/09/2006 (2:30 pm)
Try this:

sceneWindow2D.loadLevel( expandFilename( "~/data/levels/level2.t2d" ) );
#17
11/09/2006 (2:44 pm)
The "~" thing won't work for loading level, did you tried what I said :
"YourProjectFolder/data/levels/insertyourlevelnamehere.t2d"

you can also use :
expandFilename( "~/data/levels/level2.t2d" )
As Thomas said
#18
11/09/2006 (2:46 pm)
YEAAAA its WORKING!!

finally! Now i can go and make those 200 levels for my game, and finish it. :)

Does all .cs files are still loaded in level2? How to unload some of them? is that possible or i have to deal with the "packages"?

It seams that TGB v1.1.0 (that i had, until few days ago), was crushing upon calling endLevel() command.

Where is the tile builder in TGB v1.1.2?
#19
11/10/2006 (4:06 am)
In v1.1.2, the tile builder is integrated within the main window. To learn how to use it, check TDN or go to your TGB directory, then go to 'Documentation' --> 'Tutorials' --> 'Feature Tutorials' --> 'Tile Maps.pdf'

hth
#20
11/18/2006 (2:46 am)
Hmmmm, but it seams that, when i try to load level from someClass::function event, the game crashes (??)
But if use it from sceneWindow class, like:

function sceneWindow2d::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{
%file = expandFileName("~/data/levels/level2.t2d");
sceneWindow2D.loadLevel( %file );
}

Everything is fine.
But i don't nead that.
Even if i write, and call:

function sceneWindow2d::SomeFunction()
{
%file = expandFileName("~/data/levels/level2.t2d");
sceneWindow2D.loadLevel( %file );
//(exact same code)
}

the game crashes.

+++++++++++++++++++++
(after some experimenting)

It looks like, that loadLevel() doesn't work when calling from some function from some class that is a mounted object.
For eg. if you have a mounted object, and he belongs to someClass:: Than, a function who wants to load level (called by that class), will crash the game.

Maybe it's not the problem in mounted object, but i cant see what else can be.
Page «Previous 1 2