Game Development Community

FileIO problem...

by Alexandre Ribeiro de Sa · in Torque Game Builder · 05/23/2007 (8:33 pm) · 8 replies

Hi, I have a small problem with fileIO, I can read file but I can't write them... Both XML and text (writeLine)...

here the code:
function writeXML()
{
   %xml = new ScriptObject() { class = "XML"; };
   if( %xml.beginWrite( expandFileName("~/data/text.xml") ) )
   {
      %xml.writeClassBegin( "Texto_de_Teste" );
         %xml.writeField( "Texto", "Hello World!" );
      %xml.writeClassEnd();
      %xml.endWrite();
   }   
   else
   {
      error("File is not open for writing");
   }   
}

function writeFile()
{
   %file = new FileObject();

   if(%file.openForWrite(expandFileName("~/data/text.txt")))
   {
      %file.writeLine("Hello World!");
      echo("File Written");
   }
   else
   {
      error("File is not open for writing");
   }
   %file.close();
   %file.delete();
}

#1
05/23/2007 (10:41 pm)
I don't use 1.5Beta and I can't say anything about XML, but you code ( writeFile() ) is works for me.
What did you get exactly?
#2
05/24/2007 (1:31 pm)
Here too, don't works on 1.5 but work on 1.4 :-/

you know a good resource to read xml files for 1.4? I don't find any here to download...
#3
05/24/2007 (3:20 pm)
There is no TGB 1.4, there is only 1.1.3 and 1.5 Beta
#4
05/24/2007 (3:53 pm)
Ops... :-/... work on 1.1.3 :p
#5
05/24/2007 (11:43 pm)
IsWriteableFileName(or any other write function) just return 0 in game mode, but return 1 in editor mode...
anyone know something about it?!
there any option to say "my game can save/create files"?


Thanks
#6
05/30/2007 (4:06 pm)
It seems I could only get openForWrite to work in "game" mode passing the entire path (including C:\... etc)... I've reported this issue.
#7
06/07/2007 (4:37 am)
@Alexandre
Maybe it's the same issue as mine. I made a topic here : www.garagegames.com/mg/forums/result.thread.php?qt=63031
For me even the screenshots aren't working.
#8
04/18/2008 (8:08 am)
I found it somewhere in this forum :

use expandFilenameFix instead expandFilename and write this code somewhere in ur codes :

function expandFilenameFix(%thePath) {
   %prePath = findfirstfile("*/game/main.cs");
   %thePath = stripChars(%thePath,"~");
   %thePath = filePath(%prePath) @ %thePath;
}

for final game change "*/game/main.cs" to "*/game/main.cs.dso" :

function expandFilenameFix(%thePath) {
   %prePath = findfirstfile("*/game/main.cs.dso");
   %thePath = stripChars(%thePath,"~");
   %thePath = filePath(%prePath) @ %thePath;
}

and yes it is not for tgb 1.7.2 ! it is for tgb 1.5 . I change the version of tgb from 1.7.2 to 1.5 !!! i want to create save file in my game directory not in "C:\Documents and Settings\mojtaba\Application Data\ ... " !!! and it is a question for me that why i cant write in my game location ??! i make screenshot of my game when saving and they save in my game directory and no way to save them in app data directory .
in tgb 1.7.2 my save files and screenshot cant be together ! lol .

sry for bad english ...