Using escape characters when reading from a file
by Noah Dyer · in Torque Game Engine · 05/03/2006 (11:45 am) · 0 replies
I was simply experimenting with my understanding of escape characters and file I/O using a test text file. The text file initially contained several lines of text exactly like this:
Thanks, Noah
Quote:I then wrote a function like this:
"\c0 Test"
"\c1 Test"
"\c2 Test"
"\c3 Test"
"\c4 Test"
"\c5 Test"
"\c6 Test"
"\c7 Test"
"\c8 Test"
"\c9 Test"
function readTest()
{
%file = new FileObject();
%file.openForRead("test.dat");
%line = 1;
while(%line !$= "")
{
%line = %file.readline();
echo(%line);
}
}When I run that in the console it outputs:Quote:instead of changing the color and outputing Test as appropriate. I thought maybe I needed to close off the color, so I changed it to:
"\c0 Test"
"\c1 Test"
"\c2 Test"
"\c3 Test"
"\c4 Test"
"\c5 Test"
"\c6 Test"
"\c7 Test"
"\c8 Test"
"\c9 Test"
Quote:But then I just got the same output with a \0 on the end. I realized it was printing the quotes to the console, so I removed the quotes from the file lines.
"\c0 Test\0"
"\c1 Test\0"
"\c2 Test\0"
"\c3 Test\0"
"\c4 Test\0"
"\c5 Test\0"
"\c6 Test\0"
"\c7 Test\0"
"\c8 Test\0"
"\c9 Test\0"
Quote:Then I still got the same output but without quotes. So my question is: What do I need to do to have my escape characters recognized as such from file input?
\c0 Test\0
\c1 Test\0
\c2 Test\0
\c3 Test\0
\c4 Test\0
\c5 Test\0
\c6 Test\0
\c7 Test\0
\c8 Test\0
\c9 Test\0
Thanks, Noah