Game Development Community

onLevelLoaded changes in 1.3 release?

by Ecliptic · in iTorque 2D · 03/03/2010 (10:14 pm) · 6 replies

I am starting to like all the changes with the engine so far and glad that I have had some time to delve into things. I have been trying to update my old project and get it working in the new version of iTGB to see how the performance is with the new changes. I realized that none of my code is working because I had been using the onLevelLoaded function in the first release of iTGB to call certain scripts and functions when that specific level is loaded. Now when you use that function the mouse disappears and I have searched and found out why in this post. http://www.torquepowered.com/community/forums/viewthread/110935

My question now is, how do you use the Scene Graph Scripting settings properly since I was probably doing things wrong before? Before I would have separate cs files executed and random functions depending on what level was loaded using..
function SCENENAME::onLevelLoaded (%this) { code }

Now that his no longer works, I am confused on what is the proper way to load certain sim sets, cs files, ect when a new level (t2d) scene is started? Or if the onLevelLoaded function is still ok to use, do I just need to re-enable mouse events and show cursor? I just want to make sure I am doing it the right way, or better yet, the most efficient way since I am not a programmer.

Thanks,
Dane

#1
03/04/2010 (6:04 am)
chances are good that you overwrite a callback thats in the Common scripts which would actually fire your script but no longer does because the function itself is never called
#2
03/04/2010 (7:42 am)
I agree 100%, in the post I referenced you had mentioned that and I see what was happening. What I am wondering now is...

"what is the proper way to load certain sim sets, cs files, ect when a new level (t2d) scene is started? Or if the onLevelLoaded function is still ok to use, do I just need to re-enable mouse events and show cursor?"

I have tried using a button to load the level and built a simple simSet object from my datablock associated with that level but that does not work either.. I can't open console for some dang reason and I haven't removed it from the common folder.... *sigh*

function GameButton::onMouseDown (%this)
{
sceneWindow2D.schedule("1","loadLevel", "game/data/levels/Easy.t2d" );

	$cheat = new t2dStaticSprite()
	{
		sceneGraph = %this;
		imageMap = "easyCheatConfig";
		class = "CheatImage"; // the class that will be associated with the object
		layer = 1; // the render layer
		size = "75 75"; // the size of the object
		position = "0 0";
	};
}


**EDIT**
Still working on this, is there a simple solution to get onLevelLoaded working like it was in the previous build of iTGB? I have hundreds of lines of code to dig through and a lot depends on that simple function. I would like to get this game working to see the performance improvements of the engine but this is becoming a nightmare for something that should have been a simple update.

Thanks
Dane
#3
03/04/2010 (12:18 pm)
There should be a few ways to work around it. You could create an object off camera that has a specific class and then use the function class::onLevelLoaded (%this, %scenegraph).

If you're feeling gutsy, you could just overwrite the function t2dSceneWindow::loadLevel(%sceneWindow, %levelFile) in the common folder, or better yet, just include its contents into your function.

Also, instead of scheduling loadlevel specifically, you can schedule a function that uses loadLevel and manages any functions you would like to run. For example:

function GameButton::onMouseDown (%this)
{
    schedule(1, 0, restartEasy);
}

function restartEasy ()
{
   sceneWindow2D.endLevel();
   %level = "game/data/levels/easy.t2d";
   sceneWindow2D.loadLevel(%level);
   initializeEasy();
}

function initializeEasy ()
{
   exec("game/scripts/otherscripts.cs");
}
#4
03/06/2010 (8:41 pm)
Well I have been trying everything... My scenegraph is called BeginnerLevel and I need this to be loaded right when the Level is loaded. I have tried putting in another object with the name BeginnerLevel and it doesn't work. If I put that back to the scenegraphs name, everything loads it just is not working properly. No mouse functions or anything... Any help wouldbe appreciated.

**EDIT**
I am looking at the code and I don't understand why it should matter if this happens OnLevelLoaded OR when I click a button... But it won't work through any other function other than an OnLevelLoaded command.

If anyone can help I would appreciate it. I need to get this done by the morning.

Dane
#5
03/08/2010 (11:09 am)
Are you making sure to end the level before loading a new one?
#6
03/12/2010 (9:43 am)
Yes, I figured out how to work around the issue fortunately but it involved me changing a good bit of my script to not use the onLevelLoaded. This would have been easier to trouble shoot if the console worked. I have been looking for a fix but I don't see anyone else with the same issue. I seen one person who deleted it out of his commons on accident but I haven't touched the commons folder.

Anyhow, I appreciate the help and sorry for the million of posts.

Thanks
Dane