Game Development Community

AddToScene troubles

by Joe Rossi · in Torque Game Builder · 01/06/2008 (2:52 pm) · 5 replies

I have written a pretty complex GUI in all script, and I'd like to move it into a scene file of it's own for easier editing.

It seems that when you call LoadLevel it erases every object in the existing scene. In future versions of TGB, it'd be nice if there were an easy way to keep an object around after loading a new level. Maybe a "persist" boolean in the sceneObject class, that would tell TGB not to delete a particular object when loading a level onto that scenegraph. Or even an "addSceneToScene" type of function to load a scene file into an existing sceneGraph.

Since (AFAIK) there is no way to do this, here's all I could come up with to try and get around it (which doesn't seem to work):
%LevelAdder = new t2dSceneWindow( ){ };  
     %LevelAdder.loadlevel( expandfilename( "game/data/levels/party_menu.t2d" )  ) ;  
     $gameWindow.getSceneGraph().addToScene( party_management_menu  );

It almost works, but I get this warning in the console, and my menu is not visible:
t2dSceneGraph::addToScene() - Object '1753' is already in a SceneGraph!.

#1
01/06/2008 (3:38 pm)
There is a persist option for scene objects, no?

If that fails, you can actually modify how objects are added to your scene when the loadlevel function is called. Check out the LevelManagment.cs file in your game/common/gamescripts folder for more details.
#2
01/06/2008 (9:06 pm)
So apparently there is a function "addtolevel" in there that does exactly what I need. Which by the way, is completely undocumented...

Thanks Phillip :D

By the way I tried the "persist" option, but that seemed to be adding the object to every scene in my game, which was not ideal for my situation since I broke my project into many scenes. I wanted to be able to keep this contained in its own scene file. Which I now can. Thanks again!
#3
01/06/2008 (11:38 pm)
Well, addtolevel is indeed documented, in the 1.1.3 documentation reference. But for instance, addtoscene and removefromscene seems to be better fits for this task.

What you forgot is to call removefromscene before addtoscene, and if you don't know in what scene the object was in before, just do
eval(%object.scene@".removefromscene("@%object@");");
and it should be work.
#4
01/07/2008 (3:42 pm)
To my knowledge addToLevel isn't anywhere in the latest documentation. I'm using TGB 1.6, not 1.1.3... so I tend to only reference the "new and improved" docs.

I get exactly what I need with one call to addToLevel. I get to keep my GUI in it's own scene file, and it loads directly into my existing scene. AddToLevel works like a charm ;)
#5
01/08/2008 (1:15 am)
The fact, is that the "new and improved" is only "new" while we wait for the improvement.
In the other hand 1.1.3 doc has great descriptions for all the most important functions. Use the both of them, and you'll have a lot less trouble finding a function.

Good thing you got the function you needed ^^