Game Development Community

File.openForWrite bug in 1.5.1 TGB

by A. Burkett · in Torque Game Builder · 10/03/2007 (4:55 pm) · 2 replies

Was testing out the fileIO on 1.5.1 Game Builder. I have a paid license, not the trial version although who knows maybe the regular license and trial versions are exactly the same. This is not the Pro version with source code distributed but the simply the licensed version although presumably the internals should also be the same.

The following snippet of code will always return an error that the "File is not open for writing". You may recognize the code as it is from the distributed Feature tutorial on FileIO:

function writeFile()

{

%file = new FileObject();


if(%file.openForWrite("~/data/files/test.txt"))

{

%file.writeLine("Hello World!");

echo("File Written");

}

else

{

error("File is not open for writing");

}

%file.close();

%file.delete();

}


This same code is working fine with the Torque Game Builder Version 1.1.3 therefore a user error is not indicated. Please look into this as there is no way to publish a real game using 1.5.1 without basic file I/O working. In the mean time we are using Version 1.1.3 which does work for this. Thanks in advance for your assitance and if there is a preferred place to put bug issues let me know and I will post there.

Also, in case people are interested, we have a fixed version of the Wack-A-Mole tutorial which doesn't crash in an in an infinite while loop like the one in the tutorial when the moles fill up. Fixed a couple problems in the tutorial. I know the art for this isn't posted in 1.5.1 like 1.1.3 however maybe the bugginess is why. If so... well we fixed it for our own use as we were going through the tutorials.

About the author

Recent Threads


#1
10/03/2007 (6:17 pm)
A couple things to get people around the problem in 1.5.1 that I can personally confirm tested (this is the same person who submitted original thread). So if you don't want to revert to 1.1.3 try this:

For writing, using the absolute filename does work so developers can use 1.5.1 for file writing. Of course one should not dream of using this workaround for actually publishing with an absolute filename unless you want your game to crash when people load it in the real world to another directory or op system. For writing:

//if(%file.openForWrite("~/data/files/test.txt")) this will work fine on 1.1.3 and needs to work for publishing

if(%file.openForWrite("C:/Games/newText/game/data/files/test.txt"))
// 1.5.1 absolute filenames only thing that works,
// your absolute filename may need to be different of course than this one

and for file reading on 1.5.1 try this:
//if(%file.openForRead("~/data/files/test.txt")) would work on 1.1.3
if(%file.openForRead("game/data/files/test.txt")) //1.5.1 limitation

So folks, this is a temporary workaround to avoid the following ;)
http://miabril.com/wp-content/uploads/2007/05/2skeleton_at_computer.gif
if you want to be on 1.5.1 and do any FileIO, good luck!
#2
10/24/2007 (4:27 pm)
I had the same problem and found this awsome work around by Isaac Barbosa.
Check it out.
http://www.garagegames.com/mg/forums/result.thread.php?qt=67663
Eyal.