Game Development Community

Open, Read, and Write Files from TorqueScript.

by TechLord · in General Discussion · 10/09/2004 (8:48 am) · 11 replies

I'm having difficulty locating TorqueScript commands to Open, Read, and Write data (ascii || binary) files from TorqueScript. I'm sure I'm overlooking something. Any assistance will be appreciated.

#1
10/09/2004 (9:01 am)
My first question is: Why do you spam the forums?

My second question is: Why don't you search the forums? The script you're looking for is easily found in the forums if you search.

Bottom line is: If you want people to take you seriously, don't spam.
#2
10/09/2004 (9:22 am)
Stefan,

I apologize if I offended you for posting in private and public 'General Discussion' forums. I've requested the private forum post to be deleted. I searched various online/offline documentation and the forums with very little luck. I would appreciate a definative answer on this topic. Thanks in advance.
#3
10/09/2004 (9:39 am)
FileObject is your friend. Do a find-in-files for FileObject in the scripts and the Engine.
#4
10/09/2004 (9:40 am)
Thanks Pat!
#5
10/09/2004 (9:46 am)
@Frankie Taylor:

Well, I think Pat answered your question but if you're anything like me (and like to read forum threads with examples and the like) then here is the one I used for reference:

www.garagegames.com/mg/forums/result.thread.php?qt=7575
Note: Private Forums.
#6
10/09/2004 (9:50 am)
TorqueScript FileObject Declaration and Methods

$file = new FileObject()
$file.openForRead(%filename)
$file.openForWrite(%filename)
$file.openForAppend(%filename)
$file.readLine(text)
$file.writeLine(text)
$file.isEOF()
$file.close();
$file.delete();
#7
10/11/2004 (10:14 am)
Unfortunately, I get a fatal error when the script is executed:(

softbullets.no-ip.com/images/filestreamerror.gif
Heres the script:
%filename = "info.dat";
%file = new fileObject();
%file.openforWrite(%fileName);
for (%x = 0;%x<%mx;%x++){
	for(%y = 0;%y<%my;%y++){
		%file.writeLine(%b[%x,%y]);
		%file.writeLine(%bv[%x,%y]);
		for(%loop = 0;%loop<4;%loop++){
			%file.writeLine(%bw[%x,%y,%loop]);
			%file.writeLine(%bwv[%x,%y,%loop]);
		}
	}
}
%file.close();
%file.delete();

I don't see a problem with the script and I did NOT experience any errors during compile of Release 1_2 torqueDemo_DEBUG.exe (vc6++). I've made no changes to any of the source code. So, I'm not really sure what the problem is.
#8
10/11/2004 (10:41 am)
Try adding a path to your filename. As I recall (don't quote me on this), there is some C functions which rejects all file names that doesn't have at least one '/' (forward slash).

Try changing "info.dat" to "/data/info.dat".
#9
10/11/2004 (10:45 am)
Doesn't look like it's opening the file. Try adding the path to the filename(Akio beat me to this by a few secs) and only do the writes if openForWrite returns true.
#10
10/11/2004 (11:27 am)
@Frankie Taylor:

I fail to see where the problem is, but I thought I'd paste a code snippit that does work, so that you can work from there, possibly?

function write(%client)
{
%file = new FileObject();
%file.openforWrite("modpath/folder/filename.cs");
%file.writeLine("any text you want to write here");
%file.close();
%file.delete();
}

You WILL need to set the path, or the script won't execute. You won't get any errors when compiling, it just won't write the file. (But from what I tested, I didn't get any errors at all, not like your popup)
#11
10/11/2004 (11:43 am)
Thanks Guys,

Adding Path to filename solve error.