Game Development Community

Save()

by Dan Phillips · in Torque Game Builder · 07/14/2007 (9:42 am) · 31 replies

I can't get save to work. This code worked in 1.3 or whatever the last version of tgb was.

$saveGameDir = "~/data/files/";

new ScriptObject(settings) {};
   
settings.currentMusicLevel = $currentMusicLevel;
settings.currentSoundLevel = $currentSoundLevel;
settings.fullscreen = isFullscreen();
   
settings.save(expandFileName($saveGameDir @ "settings.cs"));
I'm on vista, I also tried saving to the user directory, didn't work.

Also, what path should I be saving to that will work in vista and xp?
Page «Previous 1 2
#1
07/14/2007 (11:22 am)
Just found the getUserDataDirectory() which I guess I should use but save() still doesn't work.
#2
07/14/2007 (6:29 pm)
Here's the correct code :
settings.save(getUserDataDirectory()  @ "/yourgame/settings.cs"));

edit : typos again
#3
07/14/2007 (7:24 pm)
Does that work for you? It doesn't work for me. I'm on Vista, going to try it on xp.
#4
07/14/2007 (7:51 pm)
Hum, I'm on xp, but the code I just typed didn't worked for me either.
So, I know another way that works, but only inside the game path :
// Another way to get the mod path by searching it
%modpath = findfirstfile("*/game/main.cs");
if(isFile(%modpath))
$mymodpath = filePath(%modpath) @ "/";
else
{
	%modpath = findFirstFile("*/game/main.cs.dso");
	$mymodpath= filePath(%modpath) @ "/";
}

// The $savegamedir
$saveGameDir = $mymodpath @ "data/files/";

// Your script unchanged
new ScriptObject(settings) {};
   
settings.currentMusicLevel = $currentMusicLevel;
settings.currentSoundLevel = $currentSoundLevel;
settings.fullscreen = isFullscreen();
   
settings.save(expandFileName($saveGameDir @ "settings.cs"));

I found it completely by chance, I don't know any other way to save that works on 1.5.


edit : Typos 3 times... I'm really really tired x[]
#5
07/14/2007 (8:08 pm)
That worked on xp and vista but then I copied my game to my program files directory just to make sure that it worked and it didn't. I remember reading somewhere that when you save files on vista you can't save them in the program files they need to be in the user's directory somewhere.
#7
07/14/2007 (9:45 pm)
I tried all night and can't get anything to work. Seems like this should work.

new ScriptObject(settings) {};
settings.currentMusicLevel = 1;
settings.save( getUserDataDirectory() @ "/gamename/settings.cs");

getUserDataDirectory() isn't writeable
#8
07/15/2007 (7:58 am)
It seems that it should. We'll have to wait for the patch to come.
#9
07/15/2007 (8:39 am)
I've bumped this up a level to get some description/documentation for you guys, since I don't know the new directory system well enough to provide a definitive answer, but please realize it is the weekend and the guys aren't (necessarily) at the office, so it might be a day or two.

I did want to ask, have you tried echoing out what the result of your concatenation is when building the data directory and file name?

Something like:

%saveFile = getUserDataDirectory() @ "/gamename/settings.cs");
echo("File name is (" @ %saveFile @ ")");

I do know you need to use expandFileName(), and I am also guessing that you are going to find a double // in your echo'ed result--getUserDataDirectory() will probably have one / at the end, and you are immediately adding another as the first character of /gamename.
#10
07/15/2007 (1:20 pm)
I tried echoing it to make sure it was right and I also tried typing absolute paths in.
#11
07/16/2007 (4:18 pm)
This is actually an engine bug that Adam and I discovered a week or two ago. It has to do with the PrefsPath (USER\Aplication Data\ on windows) not being added to the resourceManager as a writable path. To fix it:

#1 - you must have TGB Pro.

#2 - open up VS and find the runEntryScript() method (it's in main.cc).

#3 - find the line where it says this:
ResourceManager->setWriteablePath(Platform::getCurrentDirectory());   
   ResourceManager->addPath( Platform::getCurrentDirectory() );

#4 - add this to right after it says that:
ResourceManager->setWriteablePath(Platform::getPrefsPath());
   ResourceManager->addPath( Platform::getPrefsPath() );
This will add "USER/Aplication Data/" as a writable path.

#5 - move those four lines to end of the method after the lines that say:
Con::evaluate(script, false, useDefaultScript ? defaultScriptName : argv[1]); 
   delete[] script;

That should do it. Recompile and try again. Let me know if it works out.
#12
07/16/2007 (5:21 pm)
Also, there are two global variables you can set in the top level main.cs to change the location of the prefs path:

$Game::CompanyName and $Game::GameName.

By default these are GarageGames and TorqueGameBuilder, so the prefs path is Application Data/GarageGames/TorqueGameBuilder.

I'll ping Justin about this to make sure it is the correct fix. I'm not sure if he had something else in mind for saving.
#13
07/16/2007 (5:28 pm)
Yes, I forgot to mention that. Also for your save game function you will need to use
%settings.save( getPrefsPath() @ "settings.cs");
and like Adam said it will be saved to Application Data/GarageGames/TorqueGameBuilder/settings.cs.
#14
07/16/2007 (5:31 pm)
@Luke
What happens if you do not have TGB Pro. When will this fix be addressed?
#15
07/16/2007 (5:32 pm)
Hmm... not sure about that one. We'll have to wait to hear from Justin.
#16
07/16/2007 (7:49 pm)
Echo(getPrefsPath()); doesn't return anything.
#17
07/16/2007 (8:05 pm)
If i do this and recompile it works

ResourceManager->setWriteablePath(Platform::getUserDataDirectory());
ResourceManager->addPath( Platform::getUserDataDirectory() );

is there any reason to use prefsPath over userDataDirectory?
#18
07/16/2007 (9:19 pm)
It half works. It saves the files fine but if I restart the game it says they are missing.
#19
07/17/2007 (9:14 am)
It looks like the function name changed with the final 1.5 release so, yes you are correct, getUserDataDirectory() is the correct function. Sorry for misleading you.

As for missing files, are you just using exec to load the file?
#20
07/17/2007 (9:52 am)
Yeah I'm using exec. If I save the files and exec them without restarting the game then it finds them but if I restart the game then exec says they are missing even though they are there and isFile() returns that they are there.

I'm also getting some error when I exec .dso files but I"ll figure that out tonight.
Page «Previous 1 2