SimGroup and safeDelete
by Bryan Edds · in Torque Game Builder · 04/05/2005 (4:05 pm) · 3 replies
Hi, I'm adding some fx2D objects to a SimGroup. Since I'm counting on the SimGroup to delete the held fx2D objects when it is destroyed, I'm wondering if the held fx2D objects are necessarily being deleted safely with SimGroup's default deletion behavior?
Just wondering... :)
Just wondering... :)
#2
Each time you remove an object from the beginning of a set or group, the remaining objects are scooted forward by one and %obj.getCount is decremented by 1. So, your code will only actually delete 1/2 of the objects contained in the set :)
Here's a much better approach -
04/05/2005 (4:34 pm)
Yeah, that's sort of what I'm doing just to be safe. But there is one very large problem with your code -Each time you remove an object from the beginning of a set or group, the remaining objects are scooted forward by one and %obj.getCount is decremented by 1. So, your code will only actually delete 1/2 of the objects contained in the set :)
Here's a much better approach -
for(%i = %set.getCount() - 1; %i > -1; %i--) %set.getObject(%i).safeDelete();
#3
04/05/2005 (4:36 pm)
Or you could just delete the set after the loop =)
Associate Anthony Rosenbaum
if(isObject(theSimSet)){ for(%i = 0; %i < theSimSet.getCount(); %i++){ %obj = theSimSet.getObject(%i); theSimSet.remove(%obj); %obj.safeDelete(); } }