Need Help in Embedding Objects for Inventory System
by Nick Zafiris · in Torque Game Engine · 12/29/2005 (4:48 am) · 7 replies
Hello, anyone know if there is a way to embed a SimGroup under a Player in order to implement a simple aggregation relationship?
For example, I have set up the following Inventory SimGroup under Player:
Then, when the player runs around and pick's up an item, I simply do:
This successfully moves the object from the MissionGroup to the Inventory SimGroup.
The problem is, if I save the Player object to disk, it only saves the handle to the Inventory SimGroup not the SimGroup itself. Here's the output:
Ideally, it should look like this:
Is this possible?
Nick
For example, I have set up the following Inventory SimGroup under Player:
%Player.Inventory = new SimGroup(Inventory)
{
class = InvManager;
};Then, when the player runs around and pick's up an item, I simply do:
%player.Inventory.add(%Item);
This successfully moves the object from the MissionGroup to the Inventory SimGroup.
The problem is, if I save the Player object to disk, it only saves the handle to the Inventory SimGroup not the SimGroup itself. Here's the output:
//--- OBJECT WRITE BEGIN ---
new Player() {
position = "151.56 200.875 39.907";
rotation = "0 0 1 80.9772";
scale = "1 1 1";
dataBlock = "PlayerBody";
[b]Inventory = "1427";[/b]
client = "1412";
mountVehicle = "1";
};
//--- OBJECT WRITE END ---Ideally, it should look like this:
//--- OBJECT WRITE BEGIN ---
new Player() {
position = "151.56 200.875 39.907";
rotation = "0 0 1 80.9772";
scale = "1 1 1";
dataBlock = "PlayerBody";
Inventory = "1427";
client = "1412";
mountVehicle = "1";
new SimGroup(Inventory) {
class = "InvManager";
new Item(HealthKit) {
position = "234.704 203.659 22.3952";
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "HealthKit";
collidable = "0";
static = "1";
rotate = "1";
};
};
};
//--- OBJECT WRITE END ---Is this possible?
Nick
#2
There was an XML object serialization resource available quite some time ago, might help saving your objects...
12/30/2005 (12:52 am)
How do you save the player object?There was an XML object serialization resource available quite some time ago, might help saving your objects...
#3
For testing purposes, I save it like this:
%player.save("starter.fps/data/saves/player.txt");
But my real way of doing it is to store all of the objects that need saving in a SaveData Simgroup like this:
SaveData.add(%player);
Then when I save the game, I do:
SaveData.save($saveLocation @ %filename);
Nick
12/30/2005 (1:08 am)
Hi Stefan, good to hear from you.For testing purposes, I save it like this:
%player.save("starter.fps/data/saves/player.txt");
But my real way of doing it is to store all of the objects that need saving in a SaveData Simgroup like this:
SaveData.add(%player);
Then when I save the game, I do:
SaveData.save($saveLocation @ %filename);
Nick
#4
Any other ideas on saving embedded objects?
01/02/2006 (3:55 am)
I saw that XML resource and it looks interesting, however it doesn't compile with 1.4 and I posted a question about it.Any other ideas on saving embedded objects?
#5
Why not walk the objects yourself, make a list, and then note their original IDs so you can do a fix-up on load?
This is a pretty standard data issue with an equally standard set of solutions. We've architected our stuff so it just didn't need solving (not as hard as it sounds ;).
01/08/2006 (1:35 am)
No - the engine doesn't necessarily know what the tree will look like, and since it's not a tree relationship you could potentially have an INFINITELY large amount of data to write out if you do it all in-place.Why not walk the objects yourself, make a list, and then note their original IDs so you can do a fix-up on load?
This is a pretty standard data issue with an equally standard set of solutions. We've architected our stuff so it just didn't need solving (not as hard as it sounds ;).
#6
And the IDs change each time you run the game how do you fix-up on load?
Just so you know what the goal is, when loading a saved game, I need a way to differentiate the player's inventory with an NPCs inventory. So if it was under each player's object I could've just accessed it like this:
%player.Inventory... or
%npc.Inventory...
And the engine would know which is which because it was saved under each player's object. Hope it makes sense.
Thanks
01/08/2006 (1:47 am)
Ben, when you say "walk the objects yourself" what do you mean? Save the Inventory SimGroup separately?And the IDs change each time you run the game how do you fix-up on load?
Just so you know what the goal is, when loading a saved game, I need a way to differentiate the player's inventory with an NPCs inventory. So if it was under each player's object I could've just accessed it like this:
%player.Inventory... or
%npc.Inventory...
And the engine would know which is which because it was saved under each player's object. Hope it makes sense.
Thanks
#7
01/18/2006 (11:38 pm)
I added the XML resource but can't get SimGroups saved under the player object. I'll have to think of another solution.
Torque Owner Nick Zafiris
Thanks!