Text file coming up blank
by Tom Lenz · in Torque Game Builder · 03/13/2009 (4:55 pm) · 7 replies
I am trying to read from a text file, but when I try and read the first line it comes up blank. I know there is information in there because I have made the text file. I have even tried remaking it.
Here is the code I'm using, although I'm 99.99% sure it works. ( I copied in from another script that I wrote that works ).
Is there any reason why one file would work while another one doesn't?
Thanks in advance
Tom
Here is the code I'm using, although I'm 99.99% sure it works. ( I copied in from another script that I wrote that works ).
%file = new FileObject();
%file.openForRead("~/game/gameScripts/test.txt");
%line = %file.readLine();
echo(%line);Is there any reason why one file would work while another one doesn't?
Thanks in advance
Tom
#2
03/13/2009 (5:24 pm)
What other information would be needed?
#3
03/13/2009 (7:33 pm)
Well, clearly something is different, otherwise we wouldn't be having this conversation.
#4
If this doesn't output anything, then there is something wrong further up in code.
03/14/2009 (5:16 am)
Try this to see if the first line of the txt file is printed. %file = new FileObject();
%file.openForRead("~/game/gameScripts/test.txt");
for(%i=0; i < 50; i++)
{
%line = %file.readLine();
echo(%i SPC %line);
}If this outputs a blank line and then the first line the txt file has an added line at the beginning. Try putting the cursor at the beginning of the file and using backspace to delete any extra lines. Also have you tried rewriting the file or is it created by code? Using select all (cntrl+a) might reveal problems in the file. If there is an added line at the beginning.If this doesn't output anything, then there is something wrong further up in code.
#5
I have also tried reading a file that I know works it is still blank. Is there a limit to the number of files you can read per game? Is there a way to clear the memory cache or something?
03/14/2009 (8:15 pm)
I have tried all of the suggestions. I have tried recreating the file over and over, nothing is working.I have also tried reading a file that I know works it is still blank. Is there a limit to the number of files you can read per game? Is there a way to clear the memory cache or something?
#6
What's the log saying?
03/14/2009 (11:30 pm)
No problem using Steven's code above (with % in front of all variables), so there must be something else here than the script code. Where are you putting it?What's the log saying?
#7
Rather than:
Thanks everyone for the help
03/14/2009 (11:39 pm)
Edit: I think I got it. It seems that when you create a file through windows it works better to use%file = new FileObject();
%file.openForRead("./test.txt");Rather than:
%file = new FileObject();
%file.openForRead("~/game/gameScripts/test.txt");Thanks everyone for the help
Torque 3D Owner Jason Ravencroft