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.
For our example, let's say a Bullet is overlapping Left Wing #2. The first thing MMF2 does is create a fresh Object Scrope list containing every object intance in the frame:

Object Scope
Ship
Bullet
Enemy #1
Enemy #2
Enemy #3
Enemy #4
Enemy #5
Enemy #6
Left Wing #1
Left Wing #2
Left Wing #3
Left Wing #4
Left Wing #5
Left Wing #6
Right Wing #1
Right Wing #2
Right Wing #3
Right Wing #4
Right Wing #5
Right Wing #6

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
Ship
Bullet
Enemy #1
Enemy #2
Enemy #3
Enemy #4
Enemy #5
Enemy #6
Left Wing #2
Right Wing #1
Right Wing #2
Right Wing #3
Right Wing #4
Right Wing #5
Right Wing #6

Then, MMF2 reads the second condition:
LeftWingID of = 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
Ship
Bullet
Enemy #2
Left Wing #2
Right Wing #1
Right Wing #2
Right Wing #3
Right Wing #4
Right Wing #5
Right Wing #6

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: Important: In both events, when you create the second condition, make sure to use Compare to one of the alterable values and not Compare two general values. This is because Compare to one of the alterable values loops through and compares every instance while Compare two general values only compares the most recently created instance. Tell me more...
10