Game Development Community

Saving SimObjects which reference other SimObjects

by James Ford · in Torque Game Builder · 08/20/2008 (8:35 pm) · 1 replies

The basic problem is this, I have simObject which need to hold some type of reference to other simObjects, and for that reference to persist between runs of the game, eg, game saving/loading.

I have a significant amount of data to keep track of in this game, and this data does not correspond to objects that actually have to exist in the scene, just data. But for convenience I have been storing it as fields on ScriptObjects and SimSets of ScriptObjects.

For example, there might be 20 Agents, represented by ScriptObjects in the SimSet named Agents, and there might be 5 Squads, represented by ScriptObjects in the SimSet named Squads. Each Squad can contain up to three agents (as in a deployable squad), so I might store these as dynamic fields called agent1,2,3.

Now the problem is, all this data must be savable and loadable. Currently I am saving game data by calling "save" on all the SimSet, and then execing those files to load. This won't work though because the object Ids will not persist between saving and loading, leaving my Squad objects with invalid ids in their fields.

A workaround is to have a global $agentId counter, and to assign each Agent an id (as a dynamic field), and then other objects that need to reference an agent can store the agentId, and resolve it to find the agent (by searching the AgentSet) as needed.

Well that seem "ok", but maybe there's a better way to do this. There is really no reason I have to use ScriptObjects and SimSets to store this data, perhaps there is a better way to go, it just needs to be exposed to script in a way that is as easy or easier to use as what I'm doing now.

#1
08/21/2008 (9:34 am)
FYI, Phil O'shea recommended a pretty good method, which is to append the id-counter number to a string ( eg. Agent101 ) and assign that as the object's name. That at least gets rid of the need to search through simsets to resolve "fake" id's. I also had though of possibly assigning a string like this as the internalName.

I'm leaning towards moving all the code to C++ though.