Saving at different filepath?
by Marleen Monroe · in Torque Game Builder · 01/26/2011 (2:52 am) · 6 replies
Hi folks, I'm still working my way through the TGB tutorials which can be found with the official documentation and I've come across a strange issue. In the FileIO tutorial you are shown the basics of creating a simple text file using a basic game script. The line of code used to open/create the file is:
if(%file.openForWrite("./game/data/test.txt"))
Now everything worked fine (once I'd worked out what an exec statement was - no tutorial up until that point had taught you them, nor did this one) and I received the message telling me the file had been written. When I went to find the file, however, it was nowhere to be seen. After digging about in the console log I actually found it at:
/Users/MyUsername/Library/Application Support/Independent/UntitledGame/game/gameScripts/game/data/test.txt
instead of within the data folder of the actual project itself, where it was meant to be. Is this normal? I'm not sure if I've made a mistake somewhere, but I really can't see anything so I'm a little unsure. I expect this is going to cause a bit of a headache when I come to loading files if they're not going to appear where I expect :/
Any help/advice on this one would be great. Also, I'm using a Mac if that helps solve the issue
if(%file.openForWrite("./game/data/test.txt"))
Now everything worked fine (once I'd worked out what an exec statement was - no tutorial up until that point had taught you them, nor did this one) and I received the message telling me the file had been written. When I went to find the file, however, it was nowhere to be seen. After digging about in the console log I actually found it at:
/Users/MyUsername/Library/Application Support/Independent/UntitledGame/game/gameScripts/game/data/test.txt
instead of within the data folder of the actual project itself, where it was meant to be. Is this normal? I'm not sure if I've made a mistake somewhere, but I really can't see anything so I'm a little unsure. I expect this is going to cause a bit of a headache when I come to loading files if they're not going to appear where I expect :/
Any help/advice on this one would be great. Also, I'm using a Mac if that helps solve the issue
About the author
#2
01/26/2011 (3:13 am)
Ah ok I guess that makes sense then, thank you. It was just very confusing because the tutorial clearly states that it will be in the same folder as your game...
#3
01/26/2011 (4:22 am)
Ah, yes - the recklessness of past developers...
#4
01/26/2011 (8:01 am)
@I need to give this a shot when I get to the office, but I think there is actually an error there. The correct function call should be saving it to /Users/MyUsername/Library/Application Support/Independent/UntitledGame/game/data/test.txt. Saving to the location of the game is correct, but it should not be adding the additional gameScripts/game/data directory. Will reply in a few hours.
#5
01/26/2011 (8:16 am)
If it's doing the wrong thing, it is really doing the right thing ;)
#6
Don't use a ./ as the opening part of the file path.
01/31/2011 (7:33 am)
@Marlene - I want you to try something. I was tinkering with the file system in iTorque 2D this weekend and I think my code my work for you. Give this a shot:if(%file.openForWrite("game/data/test.txt"))Don't use a ./ as the opening part of the file path.
Torque 3D Owner Ronny Bangsund
Torque Cheerleaders
Modern operating systems are built for multi-user purposes, and the clean way to save data is to store it in your home folder somewhere. Program bundles and their install directory are strictly read-only, accord to the OS guidelines. Console logs may be written alongside the app at the moment, but those of us with source have already fixed this.
Nothing to solve - everything is working as intended ;)