Game Development Community

Destroying torquescript objects

by Novack · in Torque Game Engine · 09/15/2007 (6:19 pm) · 4 replies

Sorry for this surely basic question, but how should I manage the simsets and simobjects created script side?

I dont know how to destroy them for example. (I have to?)

Maybe someone could orient me to where I can read about this, or someone with enough time could give me some conceptual hints on this matter?

#1
09/15/2007 (6:25 pm)
Simsets, like any object can be deleted from script by invoking the delete() method:

$mySimSet = new Simset();
MissionGroup.add($mySimSet);
$mySimSet.delete();

This code also adds the Simset to the MissionGroup so it will automaticly be deleted when the mission is over.

More information can be found in the TDN:
tdn.garagegames.com/wiki/TGB/Reference:_SimSet

Hope that helps.
#2
09/15/2007 (6:38 pm)
Thanks Peter. I thought it would be pretty obvious, but I wanna be sure and could not find that on TDN (actually I read that link continuously, but its not there how to destroy it), so... thank you.

Edit.: and that about MissionGroup was useful too!
#3
09/15/2007 (7:54 pm)
This is how I delete everything in a simgroup, without deleting the group (usually because I want to rebuild the group of objects for some reason without having to worry about where to recreate the group at.)
The main trick is deleting them from the back frontwards because deleting them changes the group indices for items after.
This probably also works when deleting just some specific items.

%group = nameToID(%groupName);
	%deletedCount = 0;
	
	if (%group != -1) {
		%count = %group.getCount();
		if (%count != 0) {
						
			for (%i = 0;%i<%count;%i++) {
				%obj = %group.getObject(%count-%i-1); 
				if (isObject(%obj)) {
					%obj.delete();
					%deletedCount++;
				}
			}
		}

	}
	echo("mymethod: " @ %deletedCount @ " objects deleted");
#4
09/15/2007 (8:26 pm)
Great trick! thank you Mathew. Everything its helping me here.