Missiongroup and cleanup

Scripting questions, discussions, etc
6 posts Page 1 of 1
Hodo33
Posts: 86
Joined: Fri Dec 29, 2017 4:34 pm
by Hodo33 » Wed Feb 27, 2019 2:14 am
Given this instance:

%obj = new Door() {
dataBlock = %block;
parentGroup = "MissionGroup";
};

Should I include this after creation ?

MissionGroup.add(%obj);

If I make the parentgroup equal to MissionGroup will it get automatically deleted on zone unload ?
Happenstance
Posts: 88
Joined: Sat Apr 11, 2015 9:08 pm
by Happenstance » Fri Mar 01, 2019 3:30 pm
I typically add the object after it's created (MissionGroup.add()) but parentGroup looks like a shortcut that does the same thing.

MissionGroup gets deleted when a mission ends and because it's a SimGroup, any objects contained within it will also be deleted.
Steve_Yorkshire
Posts: 328
Joined: Tue Feb 03, 2015 10:30 pm
 
by Steve_Yorkshire » Mon Mar 04, 2019 9:54 pm
As @ Happenstance missionGroup gets deleted when the server ends. If you want a parentgroup which lasts through multiple missions you can test to see if it needs creating at either missionLoad/StartGame or mainMenu::onWake().

I tend to have a check in mainMenu::onWake() and create the group if it does not already exist or empty all the objects if the group is found (eg: you're back at the mainMenu because the whole game is over, so delete all the data that you've been saving in the group which will mostly be scriptObjects)

eg:
function MainMenuGui::onWake(%this)
{
   %group = masterCleanUp;
   if(!isObject(%group))
   {
      %strat = new SimGroup(masterCleanUp);
		echo("\c4New masterCleanUp");
	}
	else
	{
      %count = %group.getCount();
	   echo("\c4masterCleanUp already exists, empty it " @ %count);
	   if(%count > 0)
	   {
	      while(%count != 0)
	      {
	         %index = %group.getObject(0);
	         if(isObject(%index))
	         {
	            //echo("deleting " @ %index SPC %index.getName());
	            %index.delete();
	         }
	         
	         //remember the escape
	         %count = %group.getCount();
	      }
	      echo("masterCleanUp emptied");
	   }
	}
}
Using that while() loop is actually a terrible way of doing this but hey :lol:

edit: should just use %group.deleteAllObjects();
function MainMenuGui::onWake(%this)
{
   %group = masterCleanUp;
   if(!isObject(%group))
   {
      %strat = new SimGroup(masterCleanUp);
		echo("\c4New masterCleanUp");
	}
	else
	{
      %count = %group.getCount();
	   echo("\c4masterCleanUp already exists, empty it " @ %count);
	   if(%count > 0)
	   {
	      %group.deleteAllObjects();
	      echo("masterCleanUp emptied");
	   }
	}
}
I'm gonna go change my code now ... :oops:
fLUnKnhaXYU
Posts: 84
Joined: Wed Nov 15, 2017 8:19 am
by fLUnKnhaXYU » Tue Mar 05, 2019 12:46 am
What will happen in the case where you group together items in a sim set , that sets the parentGroup of the item to the name of the sim set .
btw my version is 3.9
Azaezel
Posts: 461
Joined: Tue Feb 03, 2015 9:50 pm
 
by Azaezel » Tue Mar 05, 2019 3:39 am
simSets are lists of refs. simGroups are lists of actual objects. Kill a set, all you're doing is killing of a bunch of pointers. kill a group, everything's gone. (it's why stuff can be in multiple sets, but only one group)
Last edited by Azaezel on Tue Mar 05, 2019 5:48 pm, edited 1 time in total.
Hodo33
Posts: 86
Joined: Fri Dec 29, 2017 4:34 pm
by Hodo33 » Tue Mar 05, 2019 4:37 pm
Thanks for all the answers.
@Steve I didn't realize you could get a count, now I can verify a clean delete, great idea...
6 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 8 guests