### Missiongroup and cleanup

Scripting questions, discussions, etc

#### Missiongroup and cleanup

Hodo33
Posts: 86
Joined: Fri Dec 29, 2017 4:34 pm
Given this instance:

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

Should I include this after creation ?

If I make the parentgroup equal to MissionGroup will it get automatically deleted on zone unload ?

#### Re: Missiongroup and cleanup

Happenstance
Posts: 88
Joined: Sat Apr 11, 2015 9:08 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.

#### Re: Missiongroup and cleanup

Steve_Yorkshire
Posts: 328
Joined: Tue Feb 03, 2015 10:30 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

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 ...

#### Re: Missiongroup and cleanup

fLUnKnhaXYU
Posts: 84
Joined: Wed Nov 15, 2017 8:19 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

#### Re: Missiongroup and cleanup

Azaezel
Posts: 461
Joined: Tue Feb 03, 2015 9:50 pm

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.

#### Re: Missiongroup and cleanup

Hodo33
Posts: 86
Joined: Fri Dec 29, 2017 4:34 pm