How do you save & load scenes/levels?
by Leroy Frederick · in Torque Game Builder · 06/19/2006 (3:47 pm) · 7 replies
Hiya all, I thought i ask the correct way on how to you save & load scenes/levels as when i attempt it, TGB just crashes! As these are file save/load commands, i may be doing something wrong that causes the crash, if not then it's a bug.
Anyway heres my code using 2 triggers as a means of quick testing
I get crashes with either one (loadScene & loadLevel) :(
Thanks in advance! :)
EDIT: Forgot to mention saveScene seems to work in that after the function call i have a Test.scn file in the specified location.
Anyway heres my code using 2 triggers as a means of quick testing
function saveTrigger::onEnter(%this, %object)
{
if (%object.class $= "StandardPlayer")
{
error("Scene Saved attempt ",%object);
mainScene.saveScene("~/data/levels/Test.scn");
}
}
function loadTrigger::onEnter(%this, %object)
{
if (%object.class $= "StandardPlayer")
{
error("Scene Load attempt ",%object);
mainScene.endLevel();
mainScene.loadScene("~/data/levels/Test.scn");
//mainScene.loadLevel("~/data/levels/Level1Stage2.t2d");
}
}I get crashes with either one (loadScene & loadLevel) :(
Thanks in advance! :)
EDIT: Forgot to mention saveScene seems to work in that after the function call i have a Test.scn file in the specified location.
#2
06/21/2006 (6:45 am)
Thanks Doug, i'll update you if this works in a while, i've gotta install tgb 1.0, just can't wait...
#3
I just went in to fool around with the editor to see if I could figure it out, and I got it working using:
I didn't try LoadScene but I would guess that it works in much the same manner.
06/21/2006 (10:55 am)
Hello again Leroy,I just went in to fool around with the editor to see if I could figure it out, and I got it working using:
sceneWindow2D.loadLevel("YourGameDir/data/levels/your_level.t2d");I didn't try LoadScene but I would guess that it works in much the same manner.
#4
All i need to do is get it to show and make my player function as normal...
And i've still yet to try the loadScene() function;
Thanks for your help and suggestions, any more tips on the above are welcomed :)
06/21/2006 (4:19 pm)
Thanks for you help Doug (believe it or not i already tried sceneWindow2D, but it still crashed), problem was it didn't like being called within a trigger so I moved it to mainScene::onUpdateScene() which works!All i need to do is get it to show and make my player function as normal...
And i've still yet to try the loadScene() function;
Thanks for your help and suggestions, any more tips on the above are welcomed :)
#5
mainScene is from the .t2d level file: '%levelContent = new t2dSceneGraph(mainScene) {'
This is the error message i get from the console:
t2dGraphField::loadStream() - Invalid Stream Header ID!
t2dParticleEmitter::loadStream() - Invalid Stream Header ID!
t2dParticleEmitter::loadStream() - Invalid Stream Header ID!
t2dSceneGraph::loadScene() - Could not create Classname '' for Scene-Load.
t2dSceneGraph::loadScene() - Could not read SceneGraph contents from file 'GameDir/data/levels/Test.scn' for Scene-Load.
any ideas?
EDIT:
Saving the file with the extension of .t2d, .sav or .dat works and loads the scene as was saved, but i get the following error in the console now:
GameDir/gameScripts/Player_Input.cs (15): Unable to find object: 'player' attempting to call function 'updateMovement'
and all the collision and everything else is dead?
06/21/2006 (5:12 pm)
Yes, got Loadlevel() working fine! Bit still sketchy on the loadScene function() though.mainScene is from the .t2d level file: '%levelContent = new t2dSceneGraph(mainScene) {'
mainScene.loadScene("GameDir/data/levels/Test.scn");This is the error message i get from the console:
t2dGraphField::loadStream() - Invalid Stream Header ID!
t2dParticleEmitter::loadStream() - Invalid Stream Header ID!
t2dParticleEmitter::loadStream() - Invalid Stream Header ID!
t2dSceneGraph::loadScene() - Could not create Classname '' for Scene-Load.
t2dSceneGraph::loadScene() - Could not read SceneGraph contents from file 'GameDir/data/levels/Test.scn' for Scene-Load.
any ideas?
EDIT:
Saving the file with the extension of .t2d, .sav or .dat works and loads the scene as was saved, but i get the following error in the console now:
GameDir/gameScripts/Player_Input.cs (15): Unable to find object: 'player' attempting to call function 'updateMovement'
and all the collision and everything else is dead?
#6
Do you see the player on the screen after the scene loads? That is, are you getting the error related to 'updateMovement' after you try to actually move the player? It's hard for me to even offer a guess, but if I was forced I'd say that you no longer have an instance of the player object, for whatever reason, after the scene has loaded -- hence the error.
-Doug
06/23/2006 (12:15 am)
Hi Leroy,Do you see the player on the screen after the scene loads? That is, are you getting the error related to 'updateMovement' after you try to actually move the player? It's hard for me to even offer a guess, but if I was forced I'd say that you no longer have an instance of the player object, for whatever reason, after the scene has loaded -- hence the error.
-Doug
#7
Yep, i think thats whats happening (the player is on the screen, but it seems the object num is no longer what it was), it's hard to tell if it's a bug or a mistake by myself? Anyway, i'll try a few other things and see what happens, probably post in the bug reports and try to get some more reactions...
New problem i'm having is after loading a level without my player sprite & it's particle mount, using
'new t2dAnimatedSprite(player) {' and 'new t2dParticleEffect(playerFlyingParticle) {'
successfully brings the player character to the screen, but no particle (it returns as visible/mounted). The wonderful world of learning....
again, thanks for your thoughts Doug
06/23/2006 (5:14 am)
Hey Doug,Yep, i think thats whats happening (the player is on the screen, but it seems the object num is no longer what it was), it's hard to tell if it's a bug or a mistake by myself? Anyway, i'll try a few other things and see what happens, probably post in the bug reports and try to get some more reactions...
New problem i'm having is after loading a level without my player sprite & it's particle mount, using
'new t2dAnimatedSprite(player) {' and 'new t2dParticleEffect(playerFlyingParticle) {'
successfully brings the player character to the screen, but no particle (it returns as visible/mounted). The wonderful world of learning....
again, thanks for your thoughts Doug
Torque Owner Doug Wetzel
In any case, the reason you may be encountering a crash is due to 'mainScene' not being set as the current sceneGraph properly. For example, you might try:
funtion loadTrigger::onLevelLoaded(%this, %scenegraph) { $mainScene = %scenegraph; }From there you could call mainScene.loadLevel(%level) in your onEnter function without it crashing on you. I presume, not having actually done such a thing myself (I just got TGB a few days ago myself, and have only scratched the surface so far), that from there your main concern is getting the file name correctly in the call.
Anyhow, if that works, let me know ... and if not, I'd be equally curious to learn and see just what you ended up doing that did work. :)
Of course, a comment by someone who has a certain and professed method for accomplishing the same would be of equal value!