cleaning up after my objects


[ Zettels Traum ] [ search / suche ]

von dp am 28.Maerz 98 um 18:35:25:

At 11:07 26.03.98 -0500, Brent Bonet wrote:

>
>Is there an equivalent to "on endSprite" with standard parent scripts? The
>script loads an Xtra and I need to unload it when the object dies to avoid
>the nasties.
>

No, you'll have to roll your own. How you do this depends very much on your
style, so this is just an example:

All my objects share a common ancestor that supplies some basic methods,
one of them, on sleep me, checks whether a reference to that Object lives
in the actorlist and if so, removes it. Another, on demolish me, checks if
that object has puppeted sprites and if so, places them outside the stage
and kills the puppets.
Now, if a particular object doesn't need those actions or rather needs
something else tbd when passing away, I include a modified handler with the
same name. The point is: I don't have to remeber what was special with just
that object, from outside I just have to call sleep(dObj) to make it
passive and demolish(dObj) to destroy its "posessions".
In order to save my hair when things get complex I have come to birth all
my objects into one property list. every object has its id hardcoded and a
method to return that id. A typical birth looks like that:

on birthObj
  global gLpObj
  set dObj = new (script "SomeObj")
  set dId  = getMyId(dObj)
  addprop gLpObj,dId,dObj 
end

Thus I can get rid of them all with a very simple routine. Another plus is
that I can find a certain object quite easy:

on getObject dId
  global gLpObj
  set dObj = getaprop(gLpObj,dId)
  if ilk ( dObj) = #instance then return dObj
end

Now, if some graphics member script feels the need to talk to the #MenueObj
since it just received a mouseUp event, the handler above comes handy.
Hardcoded globals could do the same but I always had problems when porting
that to another project.
Best regards

Daniel Plaenitz

• Vital papers demonstrate their vitality
by leaving the place where you left them
for a place where you can't find them.



Dazu:























D. Plänitz