Game Development Community

Writting a xml

by Bruno · in Torque Game Builder · 04/20/2008 (12:31 pm) · 2 replies

Hi,

I'm adding a function similar to this one (this one was taken from common\gamescripts\properties.cs).
However, xml.beginWrite fails, no matter what i put there, and so does the original tgb function.
Is this supose to work ? Is it possible to write xml files or not ?
thanks,
Bruno



function _saveGameConfigurationData( %projectFile )
{
%xml = new ScriptObject() { class = "XML"; };
if( %xml.beginWrite( %projectFile ) )
{
%xml.writeClassBegin( "TorqueGameConfiguration" );
%xml.writeField( "Company", $Game::CompanyName );
%xml.writeField( "GameName", $Game::ProductName );
%xml.writeField( "Resolution", $Game::Resolution );
%xml.writeField( "FullScreen", $Game::FullScreen );
%xml.writeField( "CommonVer", $Game::CommonVersion );
%xml.writeField( "ConsoleKey", $Game::ConsoleBind );
%xml.writeField( "ScreenShotKey", $Game::ScreenshotBind );
%xml.writeField( "FullscreenKey", $Game::FullscreenBind );
%xml.writeField( "UsesNetwork", $Game::UsesNetwork );
%xml.writeField( "UsesAudio", $Game::UsesAudio );
%xml.writeField( "DefaultScene", $Game::DefaultScene );
%xml.writeClassEnd();
%xml.endWrite();
}

#1
04/20/2008 (12:48 pm)
Where exactly are you trying to write to and does it give any errors?

I don't think you can use relative paths when handling files so you need to do something like:

%fileName = "game/data/userProfiles.xml";
// or
%fileName = expandFileName("~/data/userProfiles.xml");

Also, remember that these files are written to the AppData/roaming folder and not to the game's folder.
#2
04/20/2008 (3:04 pm)
Well, it just fails the xml.beginWrite , i can't get anything to write.
Here's my actual source, but the one up there also fails.

It fails in this line :
if( %xml.beginWrite( %fileName ) )


%fileName = expandFileName("~/game/data/user.xml");
  
   %xml = new ScriptObject() { class = "XML"; };
   if( %xml.beginWrite( %fileName ) )
   {
      %xml.writeClassBegin( "CityHall" );
         %current_object = GroupBuilding99.getObject(0);
          %xml.writeField( "built", %current_object.built );
      %xml.writeClassEnd();