File problem
by Steven Hine · in Torque Game Builder · 06/16/2008 (6:07 pm) · 13 replies
This code should work, but alas it doesn't. A new save file is not created or saved to. Anyone see something I don't?
function HighScores::onLevelLoaded(%this, %scenegraph)
{
%this.LoadScores(expandFileName("~/data/files/HighScores.txt"));
%this.SaveNewScores(expandFileName("~/data/files/HighScores2.txt"));
}
function HighScores::SaveNewScores(%this, %fileName)
{
//create file object
%file = new FileObject();
//open file for read
if(%file.openForWrite(%fileName))
{
echo("File being updated");
%temp = pScore1.text;
echo("1 " @ %temp);
%file.writeLine( "this should work");
%temp = pScore2.text;
echo("2 " @ %temp);
%file.writeLine( %temp);
echo("High Scores file saved.");
}else{
echo("File cannot be written");
}
%file.close();
%file.delete();
}About the author
#2
06/16/2008 (6:37 pm)
Nope, atleast I don't think so. i searched my entire harddrive for the file and its not there...
#3
Someone else in the forums reported not being able to find it with searching either, but it turned out it was there. I'd recommend finding the appdata folder for your game with windows explorer so you'll know for sure.
06/16/2008 (7:54 pm)
I didn't see anything wrong with your code. Is the "File cannot be written" or "file being updated" getting hit? Someone else in the forums reported not being able to find it with searching either, but it turned out it was there. I'd recommend finding the appdata folder for your game with windows explorer so you'll know for sure.
#4
Take note of the above Steven and do another search.
06/16/2008 (9:05 pm)
Quote:On Windows XP this folder is located in %userprofile%\Application Data. However on Windows Vista this location was changed to %userprofile%\AppData\Local. On certain systems, these paths may be hidden from view. Refer to your OS documentation for instructions on how to find these locations.
Take note of the above Steven and do another search.
#5
06/17/2008 (5:37 am)
Yeah, who knows what important folders Vista has hidden for your safety and convenience.
#6
(On a side note, my file isn't being loaded from the right folder. lol)
06/17/2008 (2:36 pm)
Ok, files are there in the %userprofile%\Application Data folder. What do I do now...(On a side note, my file isn't being loaded from the right folder. lol)
#7
06/17/2008 (3:39 pm)
As the tdn doc says, if a file of the same name exists in both the project folder and the appData folder, TGB will always load the one in appData. Does that answer your question?
#8
Why does it save to the appliaction Data folder?
and
How do you stop it?
06/17/2008 (6:46 pm)
Ok... that was a silly question! Here's another:Why does it save to the appliaction Data folder?
and
How do you stop it?
#9
2.) I've managed to get a level to save over the default level being played each time the game is executed, so it is possible. I'll find a link to that thread.
EDIT:
Check this thread out:
www.garagegames.com/mg/forums/result.thread.php?qt=72837
In it, I explain how to save a level into the game/data/levels folder. Its a little sketchy, but it works.
06/17/2008 (7:12 pm)
1.) Because Vista doesn't allow programs to write to Program Files2.) I've managed to get a level to save over the default level being played each time the game is executed, so it is possible. I'll find a link to that thread.
EDIT:
Check this thread out:
www.garagegames.com/mg/forums/result.thread.php?qt=72837
In it, I explain how to save a level into the game/data/levels folder. Its a little sketchy, but it works.
#10
06/17/2008 (7:46 pm)
Ok. I get the idea, but I use XP and all this seems silly to me. Why can't files be saved to the folder I want them to be?
#11
I sugges that you read through the wiki page, seriously.
06/17/2008 (9:05 pm)
Steven, the idea is that when a game is installed, it is placed in a folder (usually Program Files) where not all users have write permissions to. To get around this, files are saved in a location that doesn't require users to have administrative privileges.Quote:I think the single biggest thing to take away from this article is that, as developers, we have no control over where an end user will install our game. This means it is foolish to use full system paths when defining the locations of our game files. Another lesson to learn here, as well, is sand-boxing file access is important. By enforcing the relative paths rule, we prevent lazy development practices, which ultimately decreases the number of potential bugs.
I sugges that you read through the wiki page, seriously.
#12
06/18/2008 (3:52 am)
Is it possible to erase data in a file? or maybe write over data?
#13
06/18/2008 (7:24 am)
I guess you didn't understand, but the method I use in the thread I gave earlier can be applied to writing any file into the base game directory. Be aware that if you use my above method, your game may not work on machines running Vista.
Associate James Ford
Sickhead Games