onLevelLoaded does not get called.
by Tyler Slabinski · in Torque Game Builder · 07/27/2010 (3:41 am) · 9 replies
I haven't used TGB since 1.1.3, so I am not sure if something changed that makes this impossible, but for some reason in 1.7.5, my scripts do not seem to want to call the onLevelLoaded functions in my script. Here is an dumbed down version I've been trying to get to work:
Gravity.cs
In the console, I get the message that "Gravity.cs is being executed", but nothing else gets executed. I have 2 objects on the scene, a star and a planet. They have a class of "starClass" and "planetClass" respectively. I looked for a solution, and even turned to the old Shooter tutorial (where I first learned the onLevelLoaded function), and even when I attempt to mimic the instructions exactly, I can't seem to get any of the functions to work.
I feel that there is a simple solution and I'm just using old material, but I am not sure what that solution is.
Gravity.cs
echo("Gravity.cs is being executed");
function starClass::onLevelLoaded(%this, %scenegraph)
{
echo("starClass::onLevelLoaded() is being executed");
}
function planetClass::onLevelLoaded(%this, %scenegraph)
{
echo("planetClass::onLevelLoaded() is being executed");
}In the console, I get the message that "Gravity.cs is being executed", but nothing else gets executed. I have 2 objects on the scene, a star and a planet. They have a class of "starClass" and "planetClass" respectively. I looked for a solution, and even turned to the old Shooter tutorial (where I first learned the onLevelLoaded function), and even when I attempt to mimic the instructions exactly, I can't seem to get any of the functions to work.
I feel that there is a simple solution and I'm just using old material, but I am not sure what that solution is.
About the author
Working on prototype.
#2
07/27/2010 (5:11 am)
Yes, the class names are there. I am 100% certain.
#3
07/27/2010 (11:51 am)
Show us the level code where these objects are defined.
#4
I must have done something wrong in the editor, because I've tried using the onAdd function, and that did not work.
07/27/2010 (3:51 pm)
PrototypeScene.t2d%levelContent = new t2dSceneGraph() {
canSaveDynamicFields = "1";
UseLayerSorting = "1";
layerSortMode0 = "Normal";
layerSortMode1 = "Normal";
layerSortMode2 = "Normal";
layerSortMode3 = "Normal";
layerSortMode4 = "Normal";
layerSortMode5 = "Normal";
layerSortMode6 = "Normal";
layerSortMode7 = "Normal";
layerSortMode8 = "Normal";
layerSortMode9 = "Normal";
layerSortMode10 = "Normal";
layerSortMode11 = "Normal";
layerSortMode12 = "Normal";
layerSortMode13 = "Normal";
layerSortMode14 = "Normal";
layerSortMode15 = "Normal";
layerSortMode16 = "Normal";
layerSortMode17 = "Normal";
layerSortMode18 = "Normal";
layerSortMode19 = "Normal";
layerSortMode20 = "Normal";
layerSortMode21 = "Normal";
layerSortMode22 = "Normal";
layerSortMode23 = "Normal";
layerSortMode24 = "Normal";
layerSortMode25 = "Normal";
layerSortMode26 = "Normal";
layerSortMode27 = "Normal";
layerSortMode28 = "Normal";
layerSortMode29 = "Normal";
layerSortMode30 = "Normal";
layerSortMode31 = "Normal";
DebugRendering = "0";
cameraPosition = "0 0";
cameraSize = "100 75";
new t2dStaticSprite() {
imageMap = "sunTopLayerImageMap";
frame = "0";
useSourceRect = "0";
sourceRect = "-1.99853 -1.99853 -1.99853 -1.99853";
canSaveDynamicFields = "1";
class = "starClass";
Position = "-32.500 -2.500";
size = "15.000 15.000";
mountID = "2";
};
new t2dStaticSprite() {
imageMap = "planetTopLayerImageMap";
frame = "0";
useSourceRect = "0";
sourceRect = "-1.99853 -1.99853 -1.99853 -1.99853";
canSaveDynamicFields = "1";
class = "planetClass";
Position = "35.000 -5.000";
mountID = "3";
};
};I must have done something wrong in the editor, because I've tried using the onAdd function, and that did not work.
#5
2. onLevelLoaded doesn't fire if you create the objects in code, after the level is loaded.
I would close the level editor and change the creation blocks to look like this:
Then run it again and see what happens.
07/27/2010 (4:08 pm)
1. onAdd doesn't fire if you create the objects in the editor.2. onLevelLoaded doesn't fire if you create the objects in code, after the level is loaded.
I would close the level editor and change the creation blocks to look like this:
new t2dStaticSprite() {
imageMap = "sunTopLayerImageMap";
class = "starClass";
Position = "-32.500 -2.500";
size = "15.000 15.000";
};
new t2dStaticSprite() {
imageMap = "planetTopLayerImageMap";
class = "planetClass";
Position = "35.000 -5.000";
//no size on this one?
};Then run it again and see what happens.
#6
EDIT: Before it's suggested, I've tried deleting the DSOs many times.
07/27/2010 (4:24 pm)
Nope, still nothing when the level gets loaded. I get the "Gravity.cs is being executed" as normal, but nothing else gets called.EDIT: Before it's suggested, I've tried deleting the DSOs many times.
#7
Give your level a class ("MyLevel") and see if onLevelLoaded gets fired for that.
07/27/2010 (4:34 pm)
Do you have files for starClass and planetClass or some other file that may be overriding the events in Gravity.cs? It would be a file that is compiled after gravity.cs.Give your level a class ("MyLevel") and see if onLevelLoaded gets fired for that.
function MyLevel::onLevelLoaded(%this)
{
echo("yay!");
}
#8
I am going to try making another project and trying that, but I am not sure if it will work.
EDIT: I am an idiot... I didn't pay attention where I was putting the exec() function in the game.cs file. I put it AFTER the loadLevel() function.
Thanks for the help.
07/27/2010 (4:42 pm)
Nothing is being compiled after Gravity.cs, but I tried your suggestion anyway and nothing different happened.I am going to try making another project and trying that, but I am not sure if it will work.
EDIT: I am an idiot... I didn't pay attention where I was putting the exec() function in the game.cs file. I put it AFTER the loadLevel() function.
Thanks for the help.
#9
07/27/2010 (4:48 pm)
Okay, cool!
praju