Object Scope


To handle multiple object instances efficient and effectively in Multimedia Fusion, it is imperative that
we understand the "Object Scope".

The Object Scope is an invisible list of all the objects (and their instances) in your frame. Every time MMF2 reads a single line of code and before it checks the conditions, it creates a new List. When it runs through the conditions, it starts REMOVING objects from the list.

Please observe the following event:
  • Health of < 20
  • : Change animation sequence to Injured
First, MMF2 creates a fresh Object Scope list. Then it reads through the list, removing every Enemy with a Health value NOT lower than 20. Finally, the animation sequence of every Enemy still remaining in the list, is changed to Injured. This being those with a Health value lower than 20.

Now, lets add a create object action:
  • Health of < 20
  • : Change animation sequence to Injured
  • : Create at (0,0) from
As before, MMF2 creates a fresh Object Scope list, removes objects not meeting the conditions and then begins executing the actions on all objects remaining in the scope. So when MMF2 creates the Blood object at (0,0) from the Enemy, it does so for each Enemy remaining in the scope. For example, if there are 5 Enemy instances, 3 with a Health value lower than 20, then 3 Blood objects are created, 1 at each Enemy.

Now, lets add an action referring to the Blood object:
  • Health of < 20
  • : Change animation sequence to Injured
  • : Create at (0,0) from
  • : Set Speed to 100
When you create an object, every other instance of that object is removed from the Object Scope. This means any subsequent actions within that event which refer to that object type will ONLY effect that newly created instance. For example, only the speed of the newly created Blood object will be set to 100, while all other existing instances remain unaffected.

Now, lets insert another action:
  • Health of < 20
  • : Change animation sequence to Injured
  • : Set Speed to 50
  • : Create at (0,0) from
  • : Set Speed to 100
MMF2 executes all actions sequentially. At the point when MMF2 executes the second action, every Blood object instance is still remaining in the Object Scope and therefore, the speed of EVERY instance will be set to 50. On the third action, a new Blood object is created. Remember that whenever you create an object, all other instances of the object are removed from the Scope. This means, the fourth action will only effect the newly created Blood object instances.

The Object Scope is also relevant when retrieving data from an object. If multiple object instances meet the conditions, then the data is only retrieved from the most recently created instance (out of those still remaining in the Scope).

For example, observe the following event:
  • Always
  • : Set Global Value A to Health( "" )
This event will always set Global Value A to the Health value of the Enemy. All values can only ever hold a single value, so if there are multiple Enemies, then MMF2 will pick the most recently created (of those remaining in the Scope) and retrieve the value from there. Unless... we specify which individual Enemy instance to retrieve it from by removing all other instances from the Scope. Ok, so how do we do that?

By using conditions which directly refer to that instance:
  • Mouse pointer is over
  • : Set Global Value A to Health( "" )
In this case, the mouse pointer will be only overlapping one single Enemy object (presumably) and the Health value is retrieved from this instance. In the event that the mouse pointer overlaps two or more Enemy objects, the most newly created of those instances is picked.

It should also be noted that:
Alterable Value A of = Alterable Value A ( "" )
is not the same thing as:
Alterable Value A of = Alterable Value A ( "" )

The first condition loops through EVERY SINGLE Enemy object checking if it's Alterable Value A is equal to the Alterable Value A of the most recently created Blood object instance, and THIS INSTANCE ONLY! If they don't match, then that Enemy instance is removed from the Object Scope and any actions will no longer effect those Enemy instances.

However, and this is the interesting part, any actions will effect ALL instances of the Blood object! Regardless as to whether their Alterable Value A matches the Alterable Value A of any Enemy objects. This is because the object you are comparing to is NOT removed from the Object Scope.

The second condition is the same, only reversed. So in this case, MMF2 will compare every Blood object against ONLY the newest Enemy object. To specify which particular Enemy instance to compare to, we would have to remove all other Enemy instances from the Object Scope, by using conditions which directly reference that instance and that instance alone, as we did with the mouse pointer condition.

The are exceptions however:
is overlapping
is the same thing as:
is overlapping

At least in terms of Object Scope, the above conditions can be regarded as the same thing. In both cases, for obvious reason, every Enemy object and every Blood object not overlapping the other is removed from the Object Scope.

However, these two conditions do differ in terms of collision detection. At the beginning of every frame, MMF2 records the location of every object. Say at the start of the frame, both an Enemy and Blood objects are overlapping, but then in a later event, you move the Blood object and now they are not overlapping. If, in a later event, you check if the Enemy is overlapping the Blood object, then a collision will be incorrectly detected because MMF2 is checking the CURRENT location of the Enemy object against the RECORDED location of the Blood object. If you were to reverse the events, making it "Blood overlapping Enemy", then a collision would be correctly be not detected, because MMF2 is now checking the current location of the Blood object (which has moved) against the recorded location of the Enemy object (which has not moved). Fortunately in most cases, you will never have to worry about this, because at the beginning of the next frame the new locations will be recorded and a collision either correctly detected or not detected.

As you can see, there is much more to Multimedia Fusion 2 than first meets the eye and understanding exactly what goes on behind the scenes is essential if you wish to enter the perilous realms of advanced programming.

Until next time, my friend.