Game Development Community

SaveScene trouble

by Jeff Trier · in Torque Game Builder · 08/14/2005 (4:48 am) · 8 replies

Hi all,

I can't seem to figure out why I get this error:

fxTileMap2D::saveTileMap() - Could not open File '' for TileMap Save.


Everything "seems" to be in order.
// first I create an fxSceneGraph2D:

new fxSceneGraph2D(t2dSceneGraph);


// then later in another function I call this:

   %file = "T2D/client/gameSaves/" @ $player::Name @ ".scn";
	t2dSceneGraph.saveScene(%file);

// I have also tried:
     t2dSceneGraph.saveScene("T2D/client/gameSaves/" @ $player::Name @ ".scn");

// and
     t2dSceneGraph.saveScene("T2D/client/gameSaves/test.scn");


Am I missing something?

Thanks again all,
-Jeff

About the author

Originally a Classical/Metal musician, I've always been attracted to anything involving computers, including: Networking, PC Building and Repair, software design and coding. I've been involved with game design and development for over 10 years.


#1
08/14/2005 (5:08 am)
Duh!

I unknowingly called it from a function I made that shared the name of a C++ function. rofl


Sorry for the clutter.
-Jeff
#2
08/14/2005 (5:48 am)
Ok well, I am feeling pretty lame.

I am now able to use saveScene, and it works great! But...

When I try and use loadScene, it gives me this error:

fxSceneGraph2D::loadScene() - Could not Read File 'T2D/client/gameSaves/Jeff.scn' for Scene Load.

I looked and the file is there.

Basically what I am doing is calling the loadScene just after the map has been built (I also tried before the map was built with the same results).

function sweepGui::onWake(%this){

	   CreateFloorPlan();

   // load map
   %map = "T2D/client/gameSaves/" @ $player::Name @ ".scn";

   if (isFile(%map))
      loadSavedMap(%map);
}

function CreateFloorPlan() {

...
   //Create tile-map.
   $playMap = new fxTileMap2D(){scenegraph = t2dSceneGraph;};

   //Load saved tile-map file.
   $playMap.loadTileMap("~/client/maps/dungeon.map");

...
}

function loadSavedMap(%file){
   if (isFile(%file)){
      echo("map exists");
   	t2dscenegraph.loadScene(%file);   	
   }

}

You will notice that I have it echo "map exists" if it finds the file, and it does.

So I guess my question is... If it detects the file as being there, why can't it be read?

I always get a little lost when things look as though they should work and they don't. If you guys could shed a little fresh perspective, I would really appreciate it.

Thanks!
-Jeff
#3
08/14/2005 (8:39 am)
There seems to be two places in the loadscene function that generates that particular error.
first is around line 1223
second is around line 1288

if (fileStream.read( &streamHeaderID ) && fileStream.read( &streamVersion ) )
OR
// Do Object Self-Serialisation.
     if ( !pSceneObject2D->loadStream( fileStream, this, ObjReferenceList, false ) )
#4
08/14/2005 (1:57 pm)
I didnt think that serialization was working yet? (maybe this isnt considered "serialization" though)
#5
08/15/2005 (6:11 am)
@David

Thanks, I took a look at the source and I am still not sure why it isn't working. I also saw this one...

if ( !fileStream.open( filename, FileStream::Read ) )

... which suggested to me that I needed to do something like this...

%file = new FileObject("sceneFile");
      sceneFile.OpenForRead(%file);
      t2dSceneGraph.loadScene(%file);

... which also didn't work for me.



@Jason

I think they are in. When I learned about the commands I visited these links:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6132


www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=7313

... and on that link Melv says, "T2D can load/save a whole scene and all its state (and has been doing for several months) using "loadScene"/"saveScene". "

I am pretty sure it's there. I am just have a tough time figuring out why it isn't working.


Thanks, I'll keep plugging away. I am sure it's something simple... unfortunatly those are the things I seem to keep overlooking. lol

[edit: mispaste]

-Jeff
#6
08/15/2005 (2:06 pm)
Can someone do a test with these 2 functions (saveScene, loadScene) and let me know if it worked for them?

edit: details

Thanks,
-Jeff
#7
08/16/2005 (10:26 am)
The scene load/save stuff does work and has since undergone a major overhaul but in v1.0.2 everything should work fine. The only downside is that all load/saves in that version didn't use the resource-manager meaning that files created via T2D calls won't be instantly available but this can be bypassed by using the "setModPath()" hack or just using a restart. The new version doesn't suffer this problem as all calls are via the resource-manager. Note that this doesn't apply to script-calls that alrady do use the resource-manager such as "FileObject". One thing to note is that, as the doco states, you should use a filename for the parameter to the sceneSave call.

Anyway, using stock T2D, add the following code to the "setupT2DScene()" function.

// ************************************************************************
	//
	// Add your custom code here...
	//
	// ************************************************************************
	
	// Load/Save Select.
	if ( true )
	{
		// Create a test sprite.
		%sprite = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
		%sprite.setPosition("20 10");
		%sprite.setImageMap( ggLogoImageMap );
		// Create another test sprite.
		%sprite = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
		%sprite.setPosition("20 -10");
		%sprite.setImageMap( tileMapImageMap );
		
		// Save the scene.
		t2dSceneGraph.saveScene("~/test.scn");
	}
	else
	{
		// Load the scene.
		t2dSceneGraph.loadScene("~/test.scn");
	}

If you run this code with "(true)", it'll create a file called "test.scn" in the root of the T2D mod directory. If you quit and change the select to "(false)", it instead loads the scene from disk.

Issues you need to deal with are locating relevant object(s) if you need to somehow control them using scripts. The next release gives you more utility on controlling this aspect though.

ADDITION: The "setModPaths" hack to use until the new version is out is to use "setModPaths(getModPaths());" which causes the resource-manager to do a rescan. You should probably keep this usage to a minimum. Again, you won't have to do this in the next release.

- Melv.
#8
08/16/2005 (11:22 am)
Melv, thank you!

Yeah, I'll have to use the setModPath hack for sure. However when I tested the loadScene before, I always restarted the engine after saveScene'ing.

I have a lot of dynamic layer tile changing and other stuff going on... so I will start with your working example in a clean script build and experiment from there (when I get off work... :p).

Thanks again for your help, this really gives me a good shove!
-Jeff