Game Development Community

Cannot Save Settings

by Jeremy Alessi · in Torque Game Builder · 08/15/2007 (6:03 pm) · 43 replies

I'm not quite sure what's happened to the old prefs system in TGB but now there's the commonConfig.xml file which saves a few settings. Unfortunately that file won't write for me.

XML::beginWrite - Failed to write to file common/commonConfig.xml.
saveGameConfigurationData - Failed to write to file: common/commonConfig.xml

This is coming up in my console. I've searched this entire site but nothing seems to be coming up for saveGameConfigurationData ... as far as bugs go.
#21
02/23/2008 (10:30 am)
Just one incomprehensible thing:

Files are being saved successfully when game is running from editor using tetraweb's fix, but nothing is saved once game is running from build compilation. What's wrong? what can I do? somebody is having the same problem and have solved it?

Thanks!
#22
02/24/2008 (7:28 am)
I wouldn't trust 1.5.1 implementation; it may be an unworkable bug. I have moved on and am happy with the saving process in 1.6 and beyond. I don't even have 1.5.1 on my system anymore, I'm afraid.

A good understanding of the new methods of saving and loading is here:
tdn.garagegames.com/wiki/TGB/FileIO

Greg
#23
02/24/2008 (7:53 am)
@Greg,

Thanks for your answer. I'm afraid that I've read that document and I don't understand how save() command was affected.

Do you say that 1.6 is saving successfully? That's great! Would you be able to explain me which method or function are you using to save in 1.6?


Thanks again!
#24
02/24/2008 (8:55 am)
@Greg,

bothering you again :)

I have updated my project from 1.5 to 1.6 and now I see it is saving here after use PlayerOneProfile.save("~/data/savedInfo/" @ $DataPlayer @ ".cs");:

Isaac/AppdData/Roaming/MyCompany/MyGame/Data/savedInfo/PlayerOneProfile.cs

And the problem is that when I start the game the saved data file is not loaded using exec("~/data/savedInfo/PlayerOneProfile.cs");

What can I do to get the saved data?

Thanks again and sorry if bother you ;)
#25
02/24/2008 (10:37 am)
I've re-read the file/IO document.

Sadly, I really can't undestand, after read that document, what to do with my code. And maybe that's because I'm not a good programmer or maybe because I need samples or more specific steps. At the end I'm really frustrated and confused.

I'm wondering if the problem is because I have a file in my game folder and there is one with the same name in the application folder?

Would somebody tell exactly how to order this? Should I use findFirstFile and findNextFile in my functions to be able to save correctly?

Thanks
#26
02/24/2008 (11:40 am)
Issac, how do you know that the file isn't being loaded? Have you used Torsion to help debug your execution, and put a breakpoint in the file itself to test if it is loaded?

It's possible that you are in fact loading the data, but over-writing it somewhere along the way, or testing for the data before it's actually been loaded, as well as many other little execution order issues that could be causing issues.
#27
02/24/2008 (12:22 pm)
@Stephen

Thanks for your answer :)

The file is not being loaded because the saved global variables are not in the game and the profile is not working just as was working in 1.5 inside TGB (it doesn't work once game is compiled).
#28
02/24/2008 (8:35 pm)
And are you getting any console errors at all?

Have you put a breakpoint (again, using Torsion) on the line that attempts to exec the file to make sure it is actually being run?
#29
02/25/2008 (6:40 am)
No errors at all.

Everything seems ok, excepth that I can't load data from the path where data is being saved.

I just can't understand why TGB is saving data in one folder while is loading from another. I'm afraid that if I can't understand this I will not be able to fix the problem.

saving in this path:

Isaac/AppData/Roaming/Independent/TorqueGameBuilder/game/data/savedInfo/playerOne.cs

loading from this path:

Documents/MyGames/LostWordTemple/Game/Data/savedinfo/playerOne.cs

Thanks
#30
02/25/2008 (8:37 am)
In the long run, running from the game editor (Builder) can lead to issues just like this one. While it's a convenient way to check levels very quickly for minor changes, since you are running from an environment that is different than what your end game will be running from when your users are playing your game, it can lead to subtle errors like the one you've had crop up on you.

The error that you are getting is that the ~ wildcard character in your path indicates "wherever our current working directory is--where we are right now in the file system). Since this can change based on where your game is installed, and where it's run from, it can be unreliable when you are running your game two different ways.

In this particular case, when you run from the editor, your working directory is within TGB's install directory, so that's where it saves the data. However, when you run from your game directory, the working directory is different--it's the second one as you indicate.

The short answer here is that you need to be consistent with what you do when working on your game. I'm guessing based on lack of response to my Torsion questions that you aren't using Torsion, which I highly recommend, and use it during just about all your game development, since the workflow and environment will be very much the same as the end user's experience (as well as all the awesome debugging capability). The "play" option from the Builder should only be used for very minor "does this look right" type things for the art work and such.

You should also have clicked the "Copy Executable" button when you first create your game project from within the Builder, as this sets up the executable to exist in your working directory like the way your end users will see it. If you did not do so, you can find the executable in your TGB installation directory, under the /tgb/gameData/T2DProject/ directory. Simply copy this to your Documents/MyGames/LostWordTemple/ directory, then rename it to be LostWordTemple.exe (name doesn't matter that much, but the default Torsion project will be looking for the rename).
#31
02/25/2008 (8:39 pm)
Isaac,

It has to do with the fact that the loading with exec looks first in the ~/game/data folder for the .cs file, and only if it can't find it does it look in the Application Data directory.

I am about to release a tutorial series that covers this aspect of saving and loading, I should have it within the week. In a nutshell, you don't want to have the same file name when you save it. So you would look for a file (fileExists) called playerOneSave.cs and if it doesn't exist, you load playerOne.cs and save it to playerOneSave.cs.

What this will then do is always load the /AppData/ modified playerOneSave.cs file when playing, unless it could not find it (first run of the game, for example) in which case it uses its always available playerOne.cs file (in ~game/data) as a template to create the playerOneSave.cs file. You just want to avoid having the same exact named file in AppData and in your ~/game paths.

I'm compressing the explanation a lot. Look for my Breakout tutorial series in the next several days for a better explanation.

Greg
#32
02/26/2008 (8:32 am)
@Greg,

Thanks for the explanation. I just can't understand one fact: If I save using a name and load using another one, in which point the second file (that contains the saved data and is loaded) will store the first one data?

I will try to understand this in the next days and of course I will be waiting for your tutorial!

@Stephen

I have been using torque since the beginning of my game, and I have run the game within torque environment a couple of times, but most of times I run the game using the play button withinh TGB (I never read an advice or warning about the eventual problem of not running the game using torsion).

I have the answers for you:

Quote:Issac, how do you know that the file isn't being loaded? Have you used Torsion to help debug your execution, and put a breakpoint in the file itself to test if it is loaded?

I've do this and everything is fine, no errors in my code and file loaded (the problem is that the file is not saved. THE FILE IS ALWAYS LOADED).

Quote:It's possible that you are in fact loading the data, but over-writing it somewhere along the way, or testing for the data before it's actually been loaded, as well as many other little execution order issues that could be causing issues.

I don't think so. I have checked every line of code calling for a save and there is no overwriting.


Quote:And are you getting any console errors at all?

Not at all, there aren't console errors reported.

Quote:Have you put a breakpoint (again, using Torsion) on the line that attempts to exec the file to make sure it is actually being run?

YES

PLUS ask for HELP, I don't know what to do :(
#33
02/26/2008 (9:31 am)
Just dont get confused:

IN 1.5

game is saving while running withing TGB environment and using gred (tetraweb) fix. game is not saving once game is compiled or running withing torsion.

IN 1.6

game is saving in user/applications/game data folder but it is loading from game directory
#34
02/28/2008 (3:43 pm)
This is really really annoying :(

EVERYTHING is working OK in my game running from TGB (development) or even running the game within TORQUE. But save() is not working once the game is built!!!

I really need to fix this and I'm unable to do it. PLEASE HELP. If somebody has solved this issue with 1.5 please let me know.

Thanks

PS for now, I don't want to upgrade to 1.6
#35
02/28/2008 (8:51 pm)
Isaac,

I suggest taking a deep breathe and taking a very deliberate read at the documentation located here:
http://tdn.garagegames.com/wiki/TGB/FileIO

When running your game stand alone (as in, not in via the editor) when you exec a script the engine will look for both a CS and a DSO in your Game Directory before attempting to read from your Application Data Directory.

This means that if you have a file called MyFile.cs in your Game Directory, AND you have a file named MyFile.cs in your Application Data Directory, then the file in your Application Data Directory will NEVER get executed.

So it is very important that when you are saving files that you give them unique names. All saved files will get saved to the Application Data Directory. Once again, when you save a file, it is saved to your Application Data Directory NOT your game's directory. This saving behavior is here to stay, as it is considered good practice for both Windows and Mac OS environments, as well as linux.

The best way, in my opinion, is to think of the Application Data Directory and the Game's Directory as one single directory. Normally, you can't have two files named the same thing and located in the same directory. So don't do that when working with the Application Data Directory and the Game's Directory. It just won't work.

When you have two files named the same thing, and one is located in the Application Data Directory and the other in the Game Directory the engine won't know which one you want to execute, so it has to make an assumption about which one you want to load. In this scenario, it was agreed upon that the engine should prefer to load files from the game directory first and only if the file doesn't exist there, would it try the Application Data Directory.
#36
02/28/2008 (9:05 pm)
In the case of something like a preference file, I suggest naming your default preference file something like defaultPrefs.cs and when you need to save out your preferences you save out to a file called customPrefs.cs, for instance.

Then in script when loading your game, you execute the defaultPrefs.cs file first, and then execute the customPrefs.cs file second.

So your defaultPrefs.cs file will be shipped with the game and be located in the Game Directory. When someone uses your game, when they save their preferences, a file customPrefs.cs, is saved out to their Application Data Directory.

Now, when your game loads, it will execute your defaultPrefs.cs file located in your Game Directory, and then it will attempt to execute the customPrefs.cs file which it tries to find in the Game Directory and fails, and then attempts to look in the Application Data Directory and succeeds.

This is just one example to help you understand.
#37
02/29/2008 (10:30 am)
Thanks Robert for your answer. I will try this. Just one question: I see that this solution works only for 1.6.

I do what you have told me and now I'm saving a file to the application data, but I can't read it with exec command... the console puts a missing file statement, so I should use something special to read from the application data instead of a simple exec(~/game/data/savedinfo/myfile.cs);?

I'm loading my files with this lines:

exec("~/data/savedInfo/PlayerOneProfile.cs");
exec("~/data/savedInfo/PlayerTwoProfile.cs");
exec("~/data/savedInfo/PlayerThreeProfile.cs");

exec("~/data/savedInfo/playerOneCustomFile.cs");

last line is not working since playerOneCustomFile.cs is in the application data directory.


what should I do to load that file? something using this?:

%search = "~/*";
for (%file = findFirstFile(%search); %file !$= ""; %file = findNextFile(%search))
echo("File:" SPC %file);

Thanks again
#38
03/01/2008 (1:12 am)
Isaac,

Have you tried dropping the ~ and specifying the full path in the exec minus the system specific path. Ie: just the path from the executable.

So for instance, if your exe is in C:\myprojects\mygame\myexe.exe and your scripts are in c:\myprojects\mygame\base\ then specify exec("base/data/savedInfo/PlayerOneCustomFile.cs");

What I'm wondering is, if the ~ is broken.
#39
03/01/2008 (7:50 am)
Robert:

If I execute this line,

exec("lostwordtemple/game/data/savedinfo/playerOneCustomFile.cs");

I get:

Missing file: C:/Users/Isaac/Documents/MyGames/Lost Word Temple TGB 16/LostWordTemple/lostwordtemple/game/data/savedinfo/playerOneCustomFile.cs!

If this one,

exec("game/data/savedinfo/playerOneCustomFile.cs");

then get:

Missing file: C:/Users/Isaac/Documents/MyGames/Lost Word Temple TGB 16/LostWordTemple/game/data/savedinfo/playerOneCustomFile.cs!

Same as if I run using "~":

exec("~/data/savedinfo/playerOneCustomFile.cs");

got:

Missing file: C:/Users/Isaac/Documents/MyGames/Lost Word Temple TGB 16/LostWordTemple/game/data/savedinfo/playerOneCustomFile.cs!


I've copied the playerOneCustomFile.cs from AppData to Documents folder and the problem is solved, but not the true one: how to read/load from the AppData folder.
#40
03/01/2008 (1:36 pm)
This one would be the correct path:
exec("game/data/savedinfo/playerOneCustomFile.cs");

But it looks like it just tries your game's directory and then quits there. Are you sure your executable is running 1.6 or above ? Are you typing that exec in your game's console pull down running standalone or in the editor console?