File IO tutorial problems...at wits end
by David Withers · in Torque Game Builder · 06/04/2008 (6:28 am) · 16 replies
Ive spent about 3 hours(waaay too long) trying to hash this out myself. And i am not convinced it is something stupid or otherwise that I am doing with the FileIO tutorial on gamebuilder.
Anyway, i have gone as far as literally copying and pasting the FILEIO code from the tutorial into a FileIO.cs. I have placed it in my gameScripts directory, and then added an exec("./FileIO.cs"); to my game.cs in the same gameScripts directory.
When i run my project, i see it loads/compiles the FileIO.cs just fine. So i know that the game.cs is loading the script.
When i do the "writeFile();" it says File written successfully, so i know its reading the function that i wrote in FileIO.cs
But when i go try to find the test.txt file, it is nowhere to be found. Any help on this would be greatly appreciated. I am not able to continue on the tutorials until i figure this out, im a little OCD about it.
<-----------FileIO.cs--------------------->
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();
}
<-----------game.cs---------------------->
function startGame(%level)
{
exec("./fileIO.cs");
Canvas.setContent(mainScreenGui);
Canvas.setCursor(DefaultCursor);
new ActionMap(moveMap);
moveMap.push();
$enableDirectInput = true;
activateDirectInput();
enableJoystick();
sceneWindow2D.loadLevel(%level);
}
//---------------------------------------------------------------------------------------------
// endGame
// Game cleanup should be done here.
//---------------------------------------------------------------------------------------------
function endGame()
{
sceneWindow2D.endLevel();
moveMap.pop();
moveMap.delete();
}
Anyway, i have gone as far as literally copying and pasting the FILEIO code from the tutorial into a FileIO.cs. I have placed it in my gameScripts directory, and then added an exec("./FileIO.cs"); to my game.cs in the same gameScripts directory.
When i run my project, i see it loads/compiles the FileIO.cs just fine. So i know that the game.cs is loading the script.
When i do the "writeFile();" it says File written successfully, so i know its reading the function that i wrote in FileIO.cs
But when i go try to find the test.txt file, it is nowhere to be found. Any help on this would be greatly appreciated. I am not able to continue on the tutorials until i figure this out, im a little OCD about it.
<-----------FileIO.cs--------------------->
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();
}
<-----------game.cs---------------------->
function startGame(%level)
{
exec("./fileIO.cs");
Canvas.setContent(mainScreenGui);
Canvas.setCursor(DefaultCursor);
new ActionMap(moveMap);
moveMap.push();
$enableDirectInput = true;
activateDirectInput();
enableJoystick();
sceneWindow2D.loadLevel(%level);
}
//---------------------------------------------------------------------------------------------
// endGame
// Game cleanup should be done here.
//---------------------------------------------------------------------------------------------
function endGame()
{
sceneWindow2D.endLevel();
moveMap.pop();
moveMap.delete();
}
#2
I am going to look that route for now.
06/04/2008 (8:13 am)
THanks, but unfortunately i have already done this thinking it may have ended up in some rogue location. But no dice. The only thing i can think of is that its hitting some read only option when it tries to close the file but doesnt show an error.I am going to look that route for now.
#3
So i guess my nex tquestion would be, how do i get game builder to see its installation, or my dev directory as its working directory, so it doesnt write these files to some crazy location. I dont want to have to specify absolute paths in my directories of course.
06/04/2008 (8:42 am)
Ok figured out it was indeed writing to a roaming profile in some crazy directory.So i guess my nex tquestion would be, how do i get game builder to see its installation, or my dev directory as its working directory, so it doesnt write these files to some crazy location. I dont want to have to specify absolute paths in my directories of course.
#4
06/04/2008 (9:40 am)
What Mike said (will say).
#5
This is documented here:
tdn.garagegames.com/wiki/TGB/FileIO
A summary from that article:
06/04/2008 (9:42 am)
You can't specify which directory to write files to, unless you have the engine source.This is documented here:
tdn.garagegames.com/wiki/TGB/FileIO
A summary from that article:
Quote:
Changes to FileObject and SimXMLDocument (for games)
* Will attempt to read from the Application Data Directory before trying the Game Directory
* Will write only to the Application Data Directory
Quote:
When writing files, the Game Directory is essentially 'mirrored' in the Application Data Directory. This is accomplished by appending the expanded relative path given to the console function onto the end of the Application Data Directory. In this way, the developer only has to refer to files via their relative path (like would normally be the case) and the engine can do the lookup automatically in both the Game Directory and the Application Data Directory without any additional effort from the developer.
#6
06/04/2008 (11:09 am)
Great, thanks for the info.
#7
07/01/2008 (4:35 pm)
We've just created a couple of functions over here that let you read/write to the desktop. I'm going to post them in the private forums tonight.
#8
I am having the same problem than David. Could you tell where the file is going please? it is the same with audio tutorial.
Thanks in advance
Learner
10/11/2008 (3:09 pm)
Hi there,I am having the same problem than David. Could you tell where the file is going please? it is the same with audio tutorial.
Thanks in advance
Learner
#9
It turns out it ended up in "C:\Documents and Settings\User\AppData\Roaming\Independent\Untitled Game"
I hope this helps.
10/11/2008 (4:00 pm)
Learner,It turns out it ended up in "C:\Documents and Settings\User\AppData\Roaming\Independent\Untitled Game"
I hope this helps.
#10
Thanks again
Learner
10/11/2008 (7:16 pm)
Thanks for the answer David, I will look for it. I think the next mandatory question is: How do I tell TGB to save/write in specific folder?Thanks again
Learner
#11
cheers
Nick
01/18/2009 (2:06 pm)
Hi, I recently got TGB. I'm checking out the basics and I got the same problem with creating a new text file - it was being saved in the same Documents and Settings location. Did a solution ever come to light for this??cheers
Nick
#12
I just got TGB too and was going through the File I/O tutorial and the file kept going to the place that David mentioned.
Is there a solution for this?
Thanks.
Brian
04/01/2009 (1:10 pm)
Hi,I just got TGB too and was going through the File I/O tutorial and the file kept going to the place that David mentioned.
Is there a solution for this?
Thanks.
Brian
#13
For the record my copy of TGB is not installed on the active partition, if that's any help, I'm far too tired from messing around with this to think of anything else.
Edit: Okay, I found it, for me it was located in C:\Users\(User)\AppData\Roaming\Independent\UntitledGame\game\data
(I use Vista)
04/12/2009 (1:31 am)
I am also having this problem, though I cannot even locate the file in the first place. Searching the entire computer turned up nothing :/For the record my copy of TGB is not installed on the active partition, if that's any help, I'm far too tired from messing around with this to think of anything else.
Edit: Okay, I found it, for me it was located in C:\Users\(User)\AppData\Roaming\Independent\UntitledGame\game\data
(I use Vista)
#14
I would prefer it if the file actually ended up where it should according to the code.
Anybody found a solution/workaround to make sure it saves to the desired location?
Or do we have to wait for it to be patched?
04/13/2009 (12:24 pm)
> Edit: Okay, I found it, for me it was located in C:\Users\(User)\AppData\Roaming\Independent\UntitledGame\game\dataI would prefer it if the file actually ended up where it should according to the code.
Anybody found a solution/workaround to make sure it saves to the desired location?
Or do we have to wait for it to be patched?
#15
No way to write file in a specific dir ?
P.S.
I don't even find the written files anyway (working on XP64)
06/04/2009 (7:33 am)
same problem :-(No way to write file in a specific dir ?
P.S.
I don't even find the written files anyway (working on XP64)
#16
Two hours (or more) to know what was happening and how to find where my files were!!! Wow!
For the umpteenth time in this thread, is there a way to manage the dirs? (If it's possible without having to buy the PRO version -I'm always hitting to the same wall- , I can't wait to Santa Claus).
Kind regards!
04/28/2010 (4:40 pm)
I'll avoid to say what comes to my mind...Two hours (or more) to know what was happening and how to find where my files were!!! Wow!
For the umpteenth time in this thread, is there a way to manage the dirs? (If it's possible without having to buy the PRO version -I'm always hitting to the same wall- , I can't wait to Santa Claus).
Kind regards!
Torque Owner Scott Johnson