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«First 1 2 Next»
#21
11/18/2006 (4:33 pm)
Instead of doing "%file = expandFileName("~/data/levels/level2.t2d");", try doing:
function sceneWindow2d::SomeFunction()
{

sceneWindow2d.loadLevel("/data/levels/level2.t2d");
}


Also, if that doesn't work, in your mousedown function, try checking if the object exists using the isObject command. If the object does exist, then load the level. TGB might be crashing because one mouse click might register as more than one. However, after the first one, the new level is loaded and the object no longer exists, so effectively the following clicks do not register.
#22
11/18/2006 (6:22 pm)
@Apurva: expandFileName() just translates the ~ into the project folder. The difference is that it will work with a packaged project even if your paths are different.

@Mirko: LoadLevel calls EndLevel before it does anything. EndLevel deletes the scenegraph and all objects inside it. If you are calling LoadLevel from a function call that is on an instance of an object that is currently in that scenegraph you'll crash TGB. The scenewindow should always be fine, but any scene object will give you this same hitch. An easy sollution is scheduling the LoadLevel for the next tick by using 0 ms as a timeout.

Try this:
SceneWindow2d.schedule( 0, LoadLevel, expandFileName( "/~data/levels/mylevel.t2d" ) );
#23
11/20/2006 (4:01 am)
@Apurva Amin got it wrong (althou, thnx for trying to help) i CAN only load level from mouse click on sceneWindow2D.

@Thomas: Thnx, this is a first concrete answer to my problem. Now i understand. I menaged to solve the problem in some other way. Since i have schedule function that loops constantly trough game calling herself, Now it also cheks wheather or not the $levelNumber is changed. If so, loadLevel()...
I'll try your solution, on another project i am working on. Thnx a lot!

Can this small tips/trics be written in "reference" documentation beside the functions? The "usage" examples of functions will be great (eg. to know where i must put sceneWindow2d.func() before some function) , and maybe this small explanations of "whats inside" (how function actually works). That will save you from a lot of FAQ-s.

Althou, i think it will be a hell of a job. :)
Maybe TGB "fans" can help. To create "fan's documentation" online, (with your aproval, what will be posted) something like wikipedia.
#24
11/20/2006 (6:49 am)
@Mirko: Glad you got it working. At the moment, there's a form of 'wikipedia' for TGB, which users can edit. It's the Torque Developer Network (TDN). It lets users write/edit articles and tutorials.
#25
11/20/2006 (10:57 am)
Anyone is more than welcome (and very much appreciated) to add documents to TDN. It definately is a community driven Torque Documentation wiki :)
#26
11/20/2006 (3:30 pm)
Oh, yea. I knew that :)

i just didn't seen it that way. There is too much articles there. I was hinking of something-like all-in-one reference document. But as l know, the FAQ documentation is in preparation stadium.

As someone said: "existing of FAQ-s are the faults of documentation"
#27
11/20/2006 (3:37 pm)
Quote:As someone said: "existing of FAQ-s are the faults of documentation"

To an extent, but if you accept that statement as true you must append something to it

existing of FAQ-s are the faults of documentation and/or peoples lack of reading the documentation.

All the answers could be there, though if you don't read it you would never know.
#28
11/20/2006 (4:17 pm)
Well, the TGB Reference will now warn users about load level in that function's documentation:
Quote:Warning: Don't call loadLevel() from a function call that is on an instance of an object that is currently in the scenegraph that is going to be deleted and replaced by the new level.
#29
11/22/2006 (7:05 am)
True, i wasn't reading everything in the docs, at the first place :P

Thats why i suggest all-in-one (script) reference document, no mather how large file is. Anyway, i am using the reference document by searching trough it (Ctrl+F) things that i nead. Or searching by index, to see if there is some function i could use.

What i am trying to say, even when i find function that i nead, there is no much of a description for it. There should be:
- parameters (some parameters are passed to func by defoult like %this)
- what function returns (if any)
- usage (sample script)
- hints/warnings (like the ones above, if any)
- "see also" hint

Althou, that would be a hell of a job, to rewrite reference doc :)

Also, it would be QL if this forum can have implemented auto-higlighting and coloring of scripts. (more and more job) :D

Another hint for some other func:
Schedule func is executing only on frames. So, for eg. if you have schedule loop every 30ms, and the game renders frames every 20ms, loop may not behave and execute as precise as you may expect.
Page«First 1 2 Next»