Saving character inventory questions
by Richard Preziosi · in Torque Game Engine · 09/01/2010 (12:39 am) · 7 replies
So I have finally completed a project enough to need to implement a save/load system. I've looked around at the resources.
www.torquepowered.com/community/resources/view/6636
www.torquepowered.com/community/resources/view/4213
www.torquepowered.com/community/blogs/view/14794
Some seem a little beyond what I am trying to do. The first one looks like the best honestly, however the way he gives an example of it is absolutely useless.
What I am attempting to do is save the inventory and ONLY the inventory, so the second one seems like it might be the best, as it is designed to "save" the inventory between missions, however I have a feeling he misuses the word save and it just ends up loading the inventory into memory, which could still be exported to a file and then loaded from the file instead of memory.
The third one is a little off from what I am trying to do, but it appears to have a feature I am interested in. The ability to associate a name with the save file.
Here is exactly what I am trying to accomplish, I have a screen with 4 selectable profiles, A, B, C and D. Each profile is a seperate game instance, and the saves need to go accordingly, if logged into profile A it should load the inventory for A, etc. I was thinking of trying this through the preferences, as I am not worried about people playing with saved files.
Does anyone have experience with a save/load system, or with any of the above systems, and could guide me in a direction to go. Any advice would be greatly appreciated.
www.torquepowered.com/community/resources/view/6636
www.torquepowered.com/community/resources/view/4213
www.torquepowered.com/community/blogs/view/14794
Some seem a little beyond what I am trying to do. The first one looks like the best honestly, however the way he gives an example of it is absolutely useless.
What I am attempting to do is save the inventory and ONLY the inventory, so the second one seems like it might be the best, as it is designed to "save" the inventory between missions, however I have a feeling he misuses the word save and it just ends up loading the inventory into memory, which could still be exported to a file and then loaded from the file instead of memory.
The third one is a little off from what I am trying to do, but it appears to have a feature I am interested in. The ability to associate a name with the save file.
Here is exactly what I am trying to accomplish, I have a screen with 4 selectable profiles, A, B, C and D. Each profile is a seperate game instance, and the saves need to go accordingly, if logged into profile A it should load the inventory for A, etc. I was thinking of trying this through the preferences, as I am not worried about people playing with saved files.
Does anyone have experience with a save/load system, or with any of the above systems, and could guide me in a direction to go. Any advice would be greatly appreciated.
#2
09/01/2010 (9:27 pm)
Also, if you're going down the preferences route, have a look at the way existing prefs are exported (in starter.fps/main.cs). All it takes is one function call to export a file with a list of global variables, then you can exec that file to load them all up again.
#3
I figure that this will be the easiest, and will only require a few ifs including $pref::Player::ProfileA, $pref::Player::ProfileB, etc. Though it will put a bit more strain on when anything is picked up as it will have to include those same ifs to update each preference for the appropriate profile.
It would be more efficient to just save a file for each profile, and have it update accordingly, believe I remember fileobject being able to save and load files. I'm just unsure about this method as I have never done anything like it.
09/01/2010 (9:50 pm)
Yeah I was thinking of using the preferences honestly, as I don't need to save anything anymore robust than something like coins, stars, and the ability to use 4 special powers.I figure that this will be the easiest, and will only require a few ifs including $pref::Player::ProfileA, $pref::Player::ProfileB, etc. Though it will put a bit more strain on when anything is picked up as it will have to include those same ifs to update each preference for the appropriate profile.
It would be more efficient to just save a file for each profile, and have it update accordingly, believe I remember fileobject being able to save and load files. I'm just unsure about this method as I have never done anything like it.
#4
Also in this block of code, is it appropriate to keep the new FileObject line? And what exactly is the .delete line doing? It's not deleting the file, so I am assuming it is just deleting the information from memory after the save is complete?
09/01/2010 (10:11 pm)
Ok so fileObject is a lot less intimidating than I was originally thinking, the question I have now is, when exactly to call the open of the file, and how exactly to set up the inventory to use the saved numbers.Also in this block of code, is it appropriate to keep the new FileObject line? And what exactly is the .delete line doing? It's not deleting the file, so I am assuming it is just deleting the information from memory after the save is complete?
function saveGameProfileA(%client)
{
%file = new FileObject();
%file.openforWrite("scriptsandassets/data/saves/profileA.cs");
%file.writeLine("any text you want to write here");
%file.close();
%file.delete();
}
#5
Unless, of course, you have multiple players at a time locally.
The FileObject route will give you basically the same effect, but with more effort and with more control over what you write into the file.
09/01/2010 (11:19 pm)
Quote:and will only require a few ifs including $pref::Player::ProfileA, $pref::Player::ProfileB, etc.Not necessarily - just have a single set of $Inventory::whatever variables loaded at any one time, and save/load using the appropriate file. For example, playerA.cs might contain
$Inventory::numStars = 5; $Inventory::numCoins = 4;And playerB.cs might contain
$Inventory::numStars = 10; $Inventory::numCoins = 1;When player B plays the game, you exec playerB.cs. When player A is playing, exec playerA.cs. No matter who is playing, you can increment $Inventory::numStars and ::numCoins. Then save the values to the correct file when you save the game.
Unless, of course, you have multiple players at a time locally.
The FileObject route will give you basically the same effect, but with more effort and with more control over what you write into the file.
Quote:And what exactly is the .delete line doing?Yes, the FileObject is an actual object that will write data to a file. It's not the file itself, though. Once you're done modifying a file, you should delete the object you used to deal with it.
#6
It will be some time before I have the money to upgrade to T3D.
Sometimes it si difficult to tell which engine (TGE, TGEA, T3D) this comments are for?
09/03/2010 (9:42 pm)
Does this system work for TGE 1.4 as I'm still using that engine!It will be some time before I have the money to upgrade to T3D.
Sometimes it si difficult to tell which engine (TGE, TGEA, T3D) this comments are for?
#7
09/03/2010 (11:15 pm)
This is all TorqueScript, which seems largely unchanged from TGE to T3D. All the methods we've discussed here should apply to 1.4.
Torque 3D Owner Matt Huston
Atomic Banzai Games
<SaveGame> <Profile id="A"> <Inventory id="1" name="Sword"/> <Inventory id="2" name="Shield"/> </Profile> ... and so on ... </SaveGame>