Game Development Community

Deleting SimSet (unable to find objects)

by Mr Zurkon · in iTorque 2D · 07/04/2011 (10:32 am) · 7 replies

Function that creates the objects:
function testSpawn(%scenegraph) {

   %rock = new t2dStaticSprite(RockA) {
      imageMap = "rock01";
      frame = "0";
      UsesPhysics="1";
      mUseSourceRect = "0";
      sourceRect = "0 0 0 0";
      canSaveDynamicFields = "1";
      Position = "-90.349 -33.945";
      size = "100.000 47.000";
      CollisionMaxIterations = "3";
      WorldLimitMode = "NULL";
      WorldLimitCallback = "1";
      WorldLimitMin = "-321.426 -185.000";
      WorldLimitMax = "320.000 300.116";
      mountID = "4";
   };
  $MySceneGraph.addToScene(%rock);
  $mySimSet.add(%rock);  
}

I'm able to call $mySimSet.getCount() and get an accurate count. However, when I attempt to delete the group a line later using $mySimSet.delete() I get "unable to find object". If the earlier function is able to find the simset (and count the objects within), then why can't it delete it as well? Am I using the wrong function?

#1
07/04/2011 (5:14 pm)
where is $mySimSet declared?

You need $mySimSet = new SimSet(); somewhere
#2
07/04/2011 (6:41 pm)
it's declared at the beginning of the game.cs script along with some other global variables.

i don't think there's anything wrong with the declaration. if there was, why would $mySimSet.getCount() work?
#3
07/05/2011 (4:44 am)
Are you trying to delete the rock object? $mySimSet.delete(); would delete the simset, not the rock. You need to write something like the following:

%rock = $mySimSet.getObject(0); // Get rock object
$mySimSet.remove(%rock); // Remove rock from SimSet
%rock.delete(); // Delete the rock object
#4
07/05/2011 (6:14 am)
I'm trying to mass-delete objects I've put in a SimSet, instead of having to delete them individually. I'm trying to find the documentation I was looking at when writing this. Are there other solutions I can use?
#5
07/05/2011 (6:18 am)
Just put that in a loop then

while($mySimSet.getCount() > 0)
{
   %rock = $mySimSet.getObject(0); // Get rock object
   $mySimSet.remove(%rock); // Remove rock from SimSet
   %rock.delete(); // Delete the rock object
}
$mySimSet.delete();
#6
07/05/2011 (6:40 am)
...i should have just done that right away. :) i'm still a bit curious why I couldn't find the objects, but I'll leave that to another time.

thanks!
#7
09/20/2011 (2:27 am)
Platform: iTorque 1.4.

Would $mySimSet.clear() automatically delete all objects in the set or simply remove them from the set but they still exist? Would simply using $mySimSet.clear() cause a memory leak? I can't seem to find the official documentation for this.