FileIO Question
by Nikki Valens · in Torque Game Builder · 11/14/2008 (4:25 pm) · 0 replies
I'm trying to do some simple file IO work but my code isn't finding the file I'm looking for.
C++ uses ".." to go to the parent folder for the directory you're in. Will the same work with torque?
The offline documentation has me use the path "~/data/files/test.txt" I've put the file I'm trying to read into that directory but it isn't reading that file, it's like it's trying to read a non-existant file.
Here is the code I'm trying to run:
function readFile()
{
%file = new FileObject();
if(%file.openForRead("~/data/files/test.txt"))
{
// Only trying to read the first line.
if(!%file.isEoF())
{
%line = %file.readLine();
echo("line = " @ %line);
}
}
else
{
echo("File not found");
}
%file.close();
%file.delete();
}
The first line of the file is "one" followed by a crlf.
The echo is returning "line = line # 1".
If I use a while loop in place of the if statement it will indeffinately read line numbers until I halt the program.
What exactly is the tilde(~) suppose to do, and what file is it using as the original directory?
C++ uses ".." to go to the parent folder for the directory you're in. Will the same work with torque?
The offline documentation has me use the path "~/data/files/test.txt" I've put the file I'm trying to read into that directory but it isn't reading that file, it's like it's trying to read a non-existant file.
Here is the code I'm trying to run:
function readFile()
{
%file = new FileObject();
if(%file.openForRead("~/data/files/test.txt"))
{
// Only trying to read the first line.
if(!%file.isEoF())
{
%line = %file.readLine();
echo("line = " @ %line);
}
}
else
{
echo("File not found");
}
%file.close();
%file.delete();
}
The first line of the file is "one" followed by a crlf.
The echo is returning "line = line # 1".
If I use a while loop in place of the if statement it will indeffinately read line numbers until I halt the program.
What exactly is the tilde(~) suppose to do, and what file is it using as the original directory?