Game Development Community

Method for saving simsets that contain other simsets?

by Ezra · in Torque Game Builder · 02/15/2006 (12:16 am) · 2 replies

I'm trying to use the .save() function for my enemydata simset, but the enemy objects in enemydata have variables that are set to other simsets, and these don't save out (they just set to the id of the simset.. even though when i originally create the simset when the enemy is made i'm giving it a name), is there a certain method I should be using to go about this?


my goal is to be able to exec the saved script file, and have it recreate all my enemies and stuff again. I'd like it so that instead of the variable showing up like this:


new t2dStaticSprite(tank1) {
//snip//
pathset = "1967";
};

it would show up like:

new t2dStaticSprite(tank1) {
//snip//
pathset = new SimSet(pathset){

//listing of my objects I had added to the pathset of tank1.pathset
};
};


I was also thinking I could step through the enemydata simset, and for each enemy check if it has one of the variables set that I know would be a simset.. and if it is a simset, I would .save() it to a temp file, and then run a function that reads that temp file using the fileObject, and writes it back out again added to another file.. and then join my enemydata file on with the other file.. so that I get all the objects created when exec'ing it.

I'm not sure if that makes sense, but I will give it a try.. unless there is an easier way :)


Also, I tried saveScene.. but it is a bit more than I need :D, since I have some variables that are still using object id's instead of names and stuff gets kinda crazy/broken when loading a previously saved scene..

#1
02/15/2006 (10:47 am)
Ok I'm not too sure on this, I'm quite new to this stuff but could you add the simSets containing the data (pathsets) to the orignal simset, so they would be saved as well? As long as the pathset variable = pathset not the id then tank1.pathset could still work. Some example code
new SimSet(enemydata) {

    new t2dStaticSprite(tank1) {
       pathset = pathset;
       //stuff with sprite here
    }
    
    new simSet(pathset){
    //stuff in here
   }
}

echo(tank1.pathset.getCount());

If it worked then it should echo the number of objects in you pathset.
#2
02/15/2006 (12:58 pm)
Cool yeah, that seems to do what I need, I think I avoided doing it that way thinking it would not work like that, but if I use unique names everything is ok...
So I changed my code so that when an enemy is added, it creates a new simset that ends up being something like "pathSetTank2" since the enemy name would be Tank2... the number isn't the actual number of enemies, it just is generic and incriments each time an enemy is added, to be sure that no enemy has the same name since I'm trying to reference everything by names instead of ID's due to being able to load/save the enemy placements..

So now, after it creates that unique simset, it adds it to the enemydata set.. and then when I save enemy data is is saving everything correctly.


I GUESS what I could have just done is use a list for the PathSet... because all I need it for is just a list of what pathnames the enemy is using.. and then the paths could just all be collected in a seperate SimSet called pathData

but either way is good.. I'm sure it has uses for other things, like mounted sub-objects maybe... I need to try that still and see what happens (when saving an object that has other objects mounted to it).