Advice needed- loading levels with different class names
by Alex Rice · in Torque Game Builder · 09/25/2006 (1:13 pm) · 3 replies
I also have noticed some namespace conflicts with class names in the Level Builder.
I have a hidden "controller" sprite that is named "level". In level 1, the "level" object is of class MyGameLevel1. In Level2, the "level" object is of class MyGameLevel2, you get the idea. I use onLevelLoaded() to activate the controller when the game is loaded. Problem is when unloading level1 and loading level 2, the engine complains about re-linking the parent class relationship (not the exact error message) for the object named "level".
Have you run into this and if so, any good workarounds. One workaround I can think of is to create a factory class that creates the controller in script.
I have a hidden "controller" sprite that is named "level". In level 1, the "level" object is of class MyGameLevel1. In Level2, the "level" object is of class MyGameLevel2, you get the idea. I use onLevelLoaded() to activate the controller when the game is loaded. Problem is when unloading level1 and loading level 2, the engine complains about re-linking the parent class relationship (not the exact error message) for the object named "level".
Have you run into this and if so, any good workarounds. One workaround I can think of is to create a factory class that creates the controller in script.
About the author
#2
09/25/2006 (1:29 pm)
Thanks Thomas, I was assuming that the 1st "level" dummy object would be deleted when the 1st level file was unloaded and before the 2nd level was loaded. But apparently is not. I will try to use the scenegraphs as you described.
#3
09/25/2006 (3:39 pm)
The object itself is deleted, but the namespace isn't. That's why you cannot change it later.
Torque Owner Thomas Buscaglia
But to answer your original question: names are unique. No two objects can have the same name. Also, no two different types of object can be linked to the same namespace (for example, you can't have a t2dStaticSprite and a t2dAnimatedSprite with the same class - one will get it and the other will give you an error). If you have common functionality that you want all levels to have and wish to use a common namespace, make sure you are using the same kind of object, preferably a scenegraph, and use the superclass field.
Edit: SP