SimXMLDocument
by Gellyware · in Torque Game Builder · 01/16/2008 (10:28 pm) · 9 replies
Can someone provide an example of how SimXMLDocument is used?
Thanks-
Thanks-
About the author
#3
Does anyone have example code and possibly an example xml file?
01/17/2008 (1:12 am)
Well, I've been trying for 2 hours and still can't get it to work for some reason.Does anyone have example code and possibly an example xml file?
#4
1. Open xml file, (beginRead( %this, %filename ))
2. Read class, (readClassBegin( %this, %class, %index ))
3. Read fields, (readField( %this, %field ))
4. Close xml file (endRead( %this ))
Here is an example:
01/17/2008 (1:35 am)
The game loads the commonConfig.xml file and reads all of the fields. Here is the basic workflow:1. Open xml file, (beginRead( %this, %filename ))
2. Read class, (readClassBegin( %this, %class, %index ))
3. Read fields, (readField( %this, %field ))
4. Close xml file (endRead( %this ))
Here is an example:
%xml = new ScriptObject() { class = "XML"; };
%file = "common/commonConfig.xml";
if( %xml.beginRead( %projectFile ) )
{
if( %xml.readClassBegin( "TorqueGameConfiguration" ) )
{
$Game::CompanyName = %xml.readField( "Company" );
...
}
%xml.endRead();
}
#5
I think I was messing up with the pathing, apparently I need to put "game/data/config.xml" instead of "~/data/config.xml".
For anyone else reading this post, rename %file (second line) to %projectFile as thats what line 3 is looking for.
01/17/2008 (12:19 pm)
Thanks, that did the trick Phillip.I think I was messing up with the pathing, apparently I need to put "game/data/config.xml" instead of "~/data/config.xml".
For anyone else reading this post, rename %file (second line) to %projectFile as thats what line 3 is looking for.
#6
%xml = new ScriptObject() { class = "XML";};
%projectfile = "common/commonConfig.xml";
if( %xml.beginWrite( %projectFile ) )
{
if (%xml.readClassBegin("TorqueGameConfiguration"))
{
%xml.writeField ("DefaultScene","~/data/levels/Level2.t2d");
}
%xml.endWrite();
}
10/06/2009 (11:43 am)
I am trying to edit the DefualtScene field at the end of a level in my commonconfig.xml using this code but it doesnt seem to work. HELP!!! :%xml = new ScriptObject() { class = "XML";};
%projectfile = "common/commonConfig.xml";
if( %xml.beginWrite( %projectFile ) )
{
if (%xml.readClassBegin("TorqueGameConfiguration"))
{
%xml.writeField ("DefaultScene","~/data/levels/Level2.t2d");
}
%xml.endWrite();
}
#7
10/06/2009 (1:28 pm)
This doesn't really answer your question of why your code isn't working but if your goal is to change the default scene, why don't you just open up the commonConfig.xml and manually edit it before you start the game? The default level only determines what level TGB will load first, editing after you start the game doesn't have any effect.
#8
10/06/2009 (6:43 pm)
I am trying to change the defualt scene from within the game so that once a level is completed when user starts the game again it starts from the level he was on. Instead of ~/data/levels/level2.t2d i will be passing a parameter after each level. I hope that makes sense. If not then sorry, i am new to game development and tgb
#9
10/06/2009 (7:10 pm)
No that makes sense, I just wasn't sure what you were doing. Your approach is a little different from mine (I use one scene for all my levels and just load new data when the user goes to a different level) but it should work. I'll take a look at the XML reader and see if I can get it to work.
Associate Phillip O'Shea
Violent Tulip
It has the basic implementation of xml files.