SceneGraph object ID used for Callback functions
by Dustin Sims · in Torque Game Builder · 12/29/2006 (11:03 pm) · 3 replies
Quick question;this is probably a newbie problem..
I have this code in game.cs that calls up my 1st Level file and it Works..
The echo statement gives me back an object ID and I assume that $Scenegraph_Name now holds
the current SceneGraph ID.
What I am trying to do is setup the callback OnLevelLoaded for that Scengraph_Name.
I thought it would be using this code but I get script errors..
It doesn't seem to like me setting up that callback function with my Global Variable $SceneGraph_Name..
I don't see any other way to get the Scengraph ID and use it to get callbacks.. (Other than setting it's name in the Level Builder, But I am trying to wrap my head around torqueScript so I want to do it all in the script file just to learn it..)
Thanks..
I have this code in game.cs that calls up my 1st Level file and it Works..
$SceneGraph_Name = sceneWindow2D.loadLevel("GameName/data/levels/Mainintro.t2d");
echo($SceneGraph_Name);The echo statement gives me back an object ID and I assume that $Scenegraph_Name now holds
the current SceneGraph ID.
What I am trying to do is setup the callback OnLevelLoaded for that Scengraph_Name.
I thought it would be using this code but I get script errors..
function $SceneGraph_Name::onLevelLoaded(%this)
{
echo ("On Level Loaded Worked");
echo(" %this = " @ %this);
%this.timerSchedule = %this.schedule(3000, LoadMainMenu);
}It doesn't seem to like me setting up that callback function with my Global Variable $SceneGraph_Name..
I don't see any other way to get the Scengraph ID and use it to get callbacks.. (Other than setting it's name in the Level Builder, But I am trying to wrap my head around torqueScript so I want to do it all in the script file just to learn it..)
Thanks..
#2
How do you tell what level just got loaded when you are in the OnlevelLoaded Callback?
From the game.cs I am doing this..
Then in another .cs file I have this.
This works but it will keep scheduling to reload the MainMenu.t2d level..
That is why I wanted Individual Scenegraph::OnLeveloaded functions..
I am going to be changing to/from a lot of levels.
I can use a Global variable and set it before i load a level and then check it in the OnlevelLoaded Callback in order to decide what level to load next.. I was thinking there should be a better/more elegant solution than trying to track the levels with a Global..
Thanks
12/30/2006 (4:07 pm)
Thanks, that works.How do you tell what level just got loaded when you are in the OnlevelLoaded Callback?
From the game.cs I am doing this..
if( isFile( "gamename/data/levels/Mainintro.t2d" ) || isFile( "gamename/data/levels/MainIntro.t2d" @ ".dso"))
{
echo("File Found");
$Main_Intro_ID = sceneWindow2D.loadLevel("gamename/data/levels/Mainintro.t2d");
echo("$Main_Intro_ID = " @ $Main_Intro_ID);
}Then in another .cs file I have this.
function t2dSceneGraph::onLevelLoaded(%this)
{
echo ("On Level Loaded Worked");
echo(" %this = " @ %this);
echo ("Scheduling...");
%this.timerSchedule = %this.schedule(3000, LoadMainMenu);
}
function t2dSceneGraph::LoadMainMenu(%this)
{
echo("Made it into Load Main Menu scheduled function");
sceneWindow2D.endLevel();
$Main_Menu_ID = sceneWindow2D.loadLevel("gamename/data/levels/MainMenu.t2d");
echo($Main_Menu_ID);
}This works but it will keep scheduling to reload the MainMenu.t2d level..
That is why I wanted Individual Scenegraph::OnLeveloaded functions..
I am going to be changing to/from a lot of levels.
I can use a Global variable and set it before i load a level and then check it in the OnlevelLoaded Callback in order to decide what level to load next.. I was thinking there should be a better/more elegant solution than trying to track the levels with a Global..
Thanks
#3
I have been looking around and have decided that to have a seperate OnLevelloaded function for each level,
I have named the Class of each of my Level SceneGraphs.
This does exactly what I wanted.
12/30/2006 (7:38 pm)
Just to update...I have been looking around and have decided that to have a seperate OnLevelloaded function for each level,
I have named the Class of each of my Level SceneGraphs.
This does exactly what I wanted.
Torque Owner Drew -Gaiiden- Sikora