Step 7: Destroy Wing Objects When Shot
When a Bullet object is overlapping a Left Wing, we want to destroy both objects, and that is easy.But, setting the LeftWingID of the parent Enemy is not so easy. If we simply added the action Set LeftWingID of Enemy to 0, it would set the LeftWingID of every Enemy instance and we don't want that!
To isolate the correct Enemy instance we need to understand the MMF2 "Object Scope". The Object Scope is a list of all the objects (and their instances) in your frame. Every time MMF2 reads a single event and before it checks the conditions, it creates a new list.
As MMF2 reads through each condition, any instance of an object referenced in that condition but NOT meeting that condition is REMOVED from the list. Once all the conditions have been read, only instances remaining in the list will be effected by the actions.
This can seem somewhat complicated at first, but create the following event and we will go through step by step how it is processed by MMF2 in terms of the Object Scope.
is overlapping
- LeftWingID of
= ID( "
" )
: Destroy
: Destroy
: Set LeftWingID to 0
| Object Scope |
|---|
Then, MMF2 reads the first condition:
is overlapping 
And every Bullet or Left Wing instance NOT overlapping the other is removed from the list, as follows:
| Object Scope |
|---|
Then, MMF2 reads the second condition:
LeftWingID of
= ID( "
" )
= ID( "
" )MMF2 loops through every single Enemy instance and compares it's LeftWingID to the ID value of the Left Wing remaining in the Scope. Any Enemy instances that DON'T match are removed from the list:
| Object Scope |
|---|
Then, MMF2 executes the actions on the objects remaining. Destroying the Bullet and Left Wing #2 and setting the LeftWingID of Enemy #2 to 0. No other Enemy or Left Wing instances are effected because they are not in the Object Scope.
The next step is to recreate the event for the Right Wing object:
is overlapping
- RightWingID of
= ID( "
" )
: Destroy
: Destroy
: Set RightWingID to 0
10