Unable to find object' when running without editor.
by Simon Jensen · in Torque Game Builder · 10/30/2006 (5:26 pm) · 16 replies
So I've got some nice fading splash screens and displaying the main menu of my game.
It works Perfectly as long as I leave the little runwitheditors block in main.cs.
But when I comment out that block I get an error in my console that the game is unable to find any of the objects I call in the main menu scripts.
Right now I'm running this at the end of the startGame function in game.cs
So the level should be loaded successfully before I do anything...
And It's being run and I don't seem to get any errors..
Is there some process of initializing the level objects that I'm missing or something?
It works Perfectly as long as I leave the little runwitheditors block in main.cs.
But when I comment out that block I get an error in my console that the game is unable to find any of the objects I call in the main menu scripts.
Right now I'm running this at the end of the startGame function in game.cs
if (%level $= "~/levels/MainMenu.t2d")
{
warn("Exec MainMenu.cs");
exec("~/gameScripts/mainMenu.cs");
warn("initMainMenu() started");
initMainMenu();
}else{ warn (" level mismatch");}specifically it's being run After the "sceneWindow2D.loadLevel(%level);" So the level should be loaded successfully before I do anything...
And It's being run and I don't seem to get any errors..
Is there some process of initializing the level objects that I'm missing or something?
#2
here's the main.cs (without comments to save space)
then I changed the game.cs as follows..
then I've got the mainMenu.cs which contains some fading functions and the controlling initMainMenu()
The MainMenu.t2d level contains 3 t2dstaticSprites..
t2dStaticSprite(MainSplashImage) (the main background image)
t2dStaticSprite(ggSplash) (the GG logo thingie)
t2dStaticSprite(whitesheet) (a blank white image w/ gradient to fade into the GG logo).
The problem is that when I run it
It says "unable to find object: 'ggSplash' when attempting to call function 'setBlendAlpha' "and "unable to find object: 'whitesheet' when attempting to call function 'schedule' "
But when I add
to the initializeProject function in the main.cs everything works just fine once I launch the game from the editor.
does that clarify it a bit?
10/30/2006 (7:56 pm)
Sure thing, here's the main.cs (without comments to save space)
function initializeProject()
{
exec("~/gui/mainScreen.gui");
exec("./gameScripts/game.cs");
startGame("~/levels/MainMenu.t2d");
}
...other functions are untouchedthen I changed the game.cs as follows..
function startGame(%level)
{
// Set The GUI.
Canvas.setContent(mainScreenGui);
Canvas.setCursor(DefaultCursor);
moveMap.push();
if( isFile( %level ) || isFile( %level @ ".dso"))
sceneWindow2D.loadLevel(%level);
warn("xx-" SPC %level);
//Level Is Loaded, Start Logic Below
if (%level $= "~/levels/MainMenu.t2d")
{
warn("Exec MainMenu.cs");
exec("~/gameScripts/mainMenu.cs");
warn("initMainMenu() started");
initMainMenu();
}else{ warn (" level mismatch");}
}then I've got the mainMenu.cs which contains some fading functions and the controlling initMainMenu()
function initMainMenu()
{ warn("++Start initMainMenu");
ggSplash.setBlendAlpha( 1 );
exec("~/gui/MainMenu.gui");
whitesheet.schedule(350,whiteFadeOut);
}The MainMenu.t2d level contains 3 t2dstaticSprites..
t2dStaticSprite(MainSplashImage) (the main background image)
t2dStaticSprite(ggSplash) (the GG logo thingie)
t2dStaticSprite(whitesheet) (a blank white image w/ gradient to fade into the GG logo).
The problem is that when I run it
It says "unable to find object: 'ggSplash' when attempting to call function 'setBlendAlpha' "and "unable to find object: 'whitesheet' when attempting to call function 'schedule' "
But when I add
if ($runWithEditors)
{
toggleLevelEditor();
return;
} to the initializeProject function in the main.cs everything works just fine once I launch the game from the editor.
does that clarify it a bit?
#3
hmm i think (not quite sure ) you should change exec funtion into exec ("./yourscript.cs")
and also change your function initializeproject into like this
function initializeProject()
{ startGame("~/levels/MainMenu.t2d"); }
hopefully it work
11/01/2006 (8:41 pm)
Sorry i late for the replyhmm i think (not quite sure ) you should change exec funtion into exec ("./yourscript.cs")
and also change your function initializeproject into like this
function initializeProject()
{ startGame("~/levels/MainMenu.t2d"); }
hopefully it work
#4
11/03/2006 (10:02 pm)
Maybe try this%file = expandFileName("~/levels/MainMenu.t2d");
startGame(%file);
#5
so
is what wound up working.
Thanks for the help gang.
11/04/2006 (6:53 am)
After waay too much prodding and poking it turns out that for some reason startGame wanted a complete path from root of the game for the level to load successfully... so
startGame("BombBots/data/levels/MainMenu.t2d");is what wound up working.
Thanks for the help gang.
#6
%file = expandFileName("~/levels/MainMenu.t2d");
startGame(%file);
What expandFileName will 'usually' do is parse out the ~ and convert it to the full path.
11/04/2006 (9:59 am)
Did you try %file = expandFileName("~/levels/MainMenu.t2d");
startGame(%file);
What expandFileName will 'usually' do is parse out the ~ and convert it to the full path.
#7
however adding the data folder in there does the trick.
%file = expandFileName("~/data/levels/MainMenu.t2d");
In retrospect knowing the solution makes all this seems obvious.
And thanks for the expandFileName thing.. didn't know about it til today.
11/04/2006 (12:10 pm)
Yeah I had tried that. however adding the data folder in there does the trick.
%file = expandFileName("~/data/levels/MainMenu.t2d");
In retrospect knowing the solution makes all this seems obvious.
And thanks for the expandFileName thing.. didn't know about it til today.
#8
11/05/2006 (5:13 am)
Wew same with me i've never heard expandfilename too
#9
supose i have a blank project named "blank". I create level_1, level_2 and save them as files (as usual)
My question is: What should i type in script, to load level_2 ? Since everything i try, is not working :((
11/06/2006 (2:49 pm)
Since you are all "in it" can i ask a simple question:supose i have a blank project named "blank". I create level_1, level_2 and save them as files (as usual)
My question is: What should i type in script, to load level_2 ? Since everything i try, is not working :((
#10
%file = expandFileName("~/data/levels/level_2.t2d");
startGame(%file);
11/07/2006 (2:57 am)
Did you try %file = expandFileName("~/data/levels/level_2.t2d");
startGame(%file);
#11
SceneWindow2D.loadLevel( %filepath );
11/07/2006 (4:18 pm)
You probably don't want to call startGame if your game is already started. You can just do this:SceneWindow2D.loadLevel( %filepath );
#12
i type only:
function sceneWindow2d::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{
if( isFile( "~/data/levels/level2.t2d" ) || isFile( "~/data/levels/level2.t2d" @ ".dso"))
echo("file is ok");
sceneWindow2D.loadLevel( "~/data/levels/level2.t2d" );
}
end cosole output is (on mouse click):
file is ok
error loading level ~/data/levels/level2.t2d. Invalid file
but all objects dessapear from screen. (???)
11/09/2006 (7:49 am)
Yea, but its not working.i type only:
function sceneWindow2d::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{
if( isFile( "~/data/levels/level2.t2d" ) || isFile( "~/data/levels/level2.t2d" @ ".dso"))
echo("file is ok");
sceneWindow2D.loadLevel( "~/data/levels/level2.t2d" );
}
end cosole output is (on mouse click):
file is ok
error loading level ~/data/levels/level2.t2d. Invalid file
but all objects dessapear from screen. (???)
#13
11/09/2006 (10:04 am)
Try changing your code to thisfunction sceneWindow2d::onMouseDown(%this, %modifier, %worldPosition, %clicks)
{
if( isFile( "~/data/levels/level2.t2d" ) || isFile( "~/data/levels/level2.t2d" @ ".dso"))
echo("file is ok");
%file = expandFileName("~/data/levels/level2.t2d");
sceneWindow2D.loadLevel( %file );
}
#14
Do i have to unload stuff from scenegraph or scenewindow? (whatever they are) :)
I supose i always have to previosly compile .dso level file right?
Does all .cs files are still loaded in level2? How to unload some of them? is that possible or i have to deal with the "packages"?
Where is the tile builder in TGB v1.1.2?
11/09/2006 (2:20 pm)
WwwweeeEEEEEEEAAA!!! Its working!!!Do i have to unload stuff from scenegraph or scenewindow? (whatever they are) :)
I supose i always have to previosly compile .dso level file right?
Does all .cs files are still loaded in level2? How to unload some of them? is that possible or i have to deal with the "packages"?
Where is the tile builder in TGB v1.1.2?
#15
Do i have to unload stuff from scenegraph or scenewindow? (whatever they are) :)
to unload a level use sceneWindow2D.endLevel(); This will cleanup all object associated with the loaded level.
I supose i always have to previosly compile .dso level file right?
when you call exec it will automatically compile the file if it hasn't been compiled already or a newer version of the cs file exists.
Does all .cs files are still loaded in level2? How to unload some of them? is that possible or i have to deal with the "packages"?
I do not think there is any way to "Unload" a script file. The small amount of resources a loaded script takes I don't see it worth trying to unload them. IF you are using functions that are named the same across levels.
You can use packages to "overload" the function.
Where is the tile builder in TGB v1.1.2?
In is now intergrated into the project library on the right hand side of the editor.
Look at the tile Map tutorial that is installed with TGB.
11/09/2006 (9:55 pm)
Congratulations on your progress.Do i have to unload stuff from scenegraph or scenewindow? (whatever they are) :)
to unload a level use sceneWindow2D.endLevel(); This will cleanup all object associated with the loaded level.
I supose i always have to previosly compile .dso level file right?
when you call exec it will automatically compile the file if it hasn't been compiled already or a newer version of the cs file exists.
Does all .cs files are still loaded in level2? How to unload some of them? is that possible or i have to deal with the "packages"?
I do not think there is any way to "Unload" a script file. The small amount of resources a loaded script takes I don't see it worth trying to unload them. IF you are using functions that are named the same across levels.
You can use packages to "overload" the function.
Where is the tile builder in TGB v1.1.2?
In is now intergrated into the project library on the right hand side of the editor.
Look at the tile Map tutorial that is installed with TGB.
#16
If i endLevel(), i just delete objects, not the script, right?
BTW, thnx a lot guys you are great, and willing to help. I appreciate that.
11/11/2006 (10:46 am)
I wanted to ask, is there a posibillity to change behavior of some classes. In level1 the class "ball" (for eg.) is acting that way, and in next level, the same class is acting different.If i endLevel(), i just delete objects, not the script, right?
BTW, thnx a lot guys you are great, and willing to help. I appreciate that.
Torque Owner Michael S
or give me the complete script of your main.cs