MissionCleanup
by Howard Dortch · in Torque Game Engine · 02/03/2005 (9:38 am) · 11 replies
I searched the forums for this but didn't see anything.
I have this called in init.cs when launching a dedicated server.
if(!isObject($PlayerUpdateObj))
{
$PlayerUpdateObj = new ScriptObject(PlayerUpdate) {};
MissionCleanup.add($PlayerUpdateObj);
$PlayerUpdateObj.think();
}
When the mission cycles, the PlayerUpdate gets canceled somehow.
At the end of onCyclePauseEnd I have to put in the same routine to get it work on the next mission.
I get a console error unknown object at the MissionCleanup.add call.
If I put echo statement at the end of the function to print out the $PlayerUpdateObj it's a different number that the one printed from the origional call in init.cs.
So the questions are.
1. if the object doesn't exist the second time why does MissionCleanup.add cause an error ?
2. since the object has a different reference number and I dont explicitly release/delete the other one does these just take up space in the game till it overflows, like a memory leak?
I have this called in init.cs when launching a dedicated server.
if(!isObject($PlayerUpdateObj))
{
$PlayerUpdateObj = new ScriptObject(PlayerUpdate) {};
MissionCleanup.add($PlayerUpdateObj);
$PlayerUpdateObj.think();
}
When the mission cycles, the PlayerUpdate gets canceled somehow.
At the end of onCyclePauseEnd I have to put in the same routine to get it work on the next mission.
I get a console error unknown object at the MissionCleanup.add call.
If I put echo statement at the end of the function to print out the $PlayerUpdateObj it's a different number that the one printed from the origional call in init.cs.
So the questions are.
1. if the object doesn't exist the second time why does MissionCleanup.add cause an error ?
2. since the object has a different reference number and I dont explicitly release/delete the other one does these just take up space in the game till it overflows, like a memory leak?
#2
02/03/2005 (12:25 pm)
Yea, MissionCleanup, ServerGroup, and MissionGroup are all deleted and remade on mission cycle. This results in all objects added to them are also deleted.
#3
So, if you want your player object to carry on from mission to mission (which, by the way, requires a lot of other handling as well), then you'll need to not put it in any of the groups Robert mentioned.
Or, you can simply continue to do what you are doing, since that is the "intended" way--keep missions completely separate, and re-generate any objects (via external information) when each mission starts.
To answer the last question about memory leaking--that's the exact reason why MissionCleanup exists in the first place--a safe and easy way to guarantee that at the end of the mission, anything in this group will be removed from memory.
02/03/2005 (12:38 pm)
As Robert mentioned, pretty much the entire purpose of the MissionCleanup() group is to do exactly what he said--delete (or "cleanup") all objects in that group at the end of the "mission". While there may be code out there (either in the engine, or in resources/snippets) that use MissionCleanup for alternative purposes, I would suggest that an examples of that are bad code--the purpose of the group is to provide a handy way to delete all objects that are appropriate for deletion at the end of the mission. Nothing else should be in there!So, if you want your player object to carry on from mission to mission (which, by the way, requires a lot of other handling as well), then you'll need to not put it in any of the groups Robert mentioned.
Or, you can simply continue to do what you are doing, since that is the "intended" way--keep missions completely separate, and re-generate any objects (via external information) when each mission starts.
To answer the last question about memory leaking--that's the exact reason why MissionCleanup exists in the first place--a safe and easy way to guarantee that at the end of the mission, anything in this group will be removed from memory.
#4
This being true then question 1 is valid, why can't I "add" something to the MissionCleanup object after a mission cycles?
question 2 goes away now.
Thanks for your time on this ......
02/03/2005 (1:30 pm)
The MissionCleanup.add(something) actually cleans up or deletes the something? Im confused with the term "add" there from what you say. It looked to me like there is a wrapper called "MissionCleanup" which can hold references or lists of things allocated or "newed" such as new scriptObject, then MissionCleanup.delete() is called to walk the list and delete everything. This being true then question 1 is valid, why can't I "add" something to the MissionCleanup object after a mission cycles?
question 2 goes away now.
Thanks for your time on this ......
#5
As to your question. You may be trying to add the object back into the MissionCleanup SimGroup before it is being recreated. I suggest searching the scripts for MissionCleanup and looking for where it is created and destroyed and make sure your adding your object in the appropriate place.
02/03/2005 (2:01 pm)
MissionCleanup is a SimGroup. The call "add" says I want a particular object added to this group. When the mission cycles MissionCleanup.delete() is called which deletes the MissionCleanup SimGroup object. It is the behavior of a SimGroup to delete all objects added to it when it itself is deleted.As to your question. You may be trying to add the object back into the MissionCleanup SimGroup before it is being recreated. I suggest searching the scripts for MissionCleanup and looking for where it is created and destroyed and make sure your adding your object in the appropriate place.
#6
Thank you all for your help.....
02/03/2005 (2:22 pm)
@Robert that is probably the case as it makes sense. I put the call after the loadMission thinking that might fix things but no go. Probably the new SimGroup( MissionCleanup ); has not been reached yet. I think I will rewrite the code to do it a different way and not add it to the MissionCleanup.Thank you all for your help.....
#7
And purely as an observation, you can clean up your code quite a bit by using the names instead of global variables to track objects. The following two if statements will function exactly the same, but you can see the differences between the two quite clearly...
02/04/2005 (4:22 am)
It sounds like what you should do is create your own group in the server init like this...if(!isObject(playerUpdates){ new SimGroup(UpdateData); }
if(!isObject($PlayerUpdateObj))
{
$PlayerUpdateObj = new ScriptObject(PlayerUpdate) {};
UpdateData.add($PlayerUpdateObj);
$PlayerUpdateObj.think();
}And purely as an observation, you can clean up your code quite a bit by using the names instead of global variables to track objects. The following two if statements will function exactly the same, but you can see the differences between the two quite clearly...
if(!isObject($PlayerUpdateObj))
{
$PlayerUpdateObj = new ScriptObject(PlayerUpdate) {};
UpdateData.add($PlayerUpdateObj);
$PlayerUpdateObj.think();
}
-------------------------------------------------------------------
if(!isObject(PlayerUpdate))
{
new ScriptObject(PlayerUpdate){};
UpdateData.add(PlayerUpdate);
PlayerUpdate.think();
}
#8
02/04/2005 (4:53 am)
@Gonzo, yeah I had it that way origionaly and changed it to a global so I could keep an eye on it better. The non global way is much prefered. The problem I was having was the clients only got updates until a mission switch then it went away. There was no need to call the update during a mission switch because there is nothing to update till the zone got loaded and player created so I figured adding to a simgroup would make it easier to cleanup. But re activating it at mission start didn't happen. Still trying to learn, thanks for the response....
#9
09/26/2005 (7:10 am)
Bump. Another question here. When you create an object and use MissionCleanup.add(%obj) and later delete the object does it get removed from the list ? The reason I want to know is I add a lot of objects and didn't want to over run memory if the user plays for along time without switching missions.
#10
That's one of the largest benefits of SimObject by the way...when you have ObjectA reference ObjectB, ObjectB also references ObjectA. That way, when ObjectB is deleted it notifies ObjectA (and any others) to stop referencing ObjectB.
09/26/2005 (8:08 am)
Yes, as long as you are using the "smart referencing" that the SimObject provides for you (everything is a simobject or higher, you are using the methods/script methods defined by stock, etc.).That's one of the largest benefits of SimObject by the way...when you have ObjectA reference ObjectB, ObjectB also references ObjectA. That way, when ObjectB is deleted it notifies ObjectA (and any others) to stop referencing ObjectB.
#11
Unable to find object: 'MissionCleanup' attempting to call function 'add'
The error message leads me to believe it thinks MissionCleanup is something I defined myself. I get this when defining my object as an Item, StaticShape, TSStatic... I still don't understand the differences exactly between all these different types.
10/24/2008 (11:02 am)
Does anyone know if an object created within an "onAdd" call needs to be added to MissionCleanup? I'm using an onAdd call to create Items and place them at the transform vectors of my mount# (NOT by mounting). In the onAdd I send that reference to MissionCleanup.add(%theObjectIJustCreated) but the console always gives me back the following error: Unable to find object: 'MissionCleanup' attempting to call function 'add'
The error message leads me to believe it thinks MissionCleanup is something I defined myself. I get this when defining my object as an Item, StaticShape, TSStatic... I still don't understand the differences exactly between all these different types.
Torque Owner J. Alan Atherton