Gains or not, who are we to dissuade people from wanting to know alternative ways of doing things, whether it's for learning purposes or just for the heck of it?
It checks for collisions by using the collision masks of the calling instance and either a specific instance or all instances of an object (depending on whether you pass an instance ID or an object ID to it). Normally, the collision mask is the same as the bounding box of the sprite that is assigned to an instance. You can also assign a separate mask, in which case that mask's bounding box will be used. It's important to note here that if an instance has no collision mask - either because it doesn't have a sprite or mask assigned or because the collision mask is 0x0px - no collisions can be registered.
Then let's cover this aspect too!
Your code always runs under a specific
scope. You can think of this as the "viewpoint" of the code. Usually, this is the scope of the instance of the object the code is in. Performing certain things like setting or reading variables, or calling functions or methods, will always be done under the currently active scope, so that one instance setting a variable will set
its own variable rather than that of another instance.
It is possible to change this scope in various ways. What this means is that one instance can essentially run code from the viewpoint of another instance, or access the variables of another instance. One such way is by using
other. There are two ways to use it, and the one being discussed here is inside a Collision event. To understand how or why
other works here, we first need to understand how Collision events work.
This can be summarized as such:
GML:
var _inst = instance_place(x, y, object_to_collide_with)
{
// Collision event code is fired here!
}
This means that a Collision event can register collisions against one instance of a particular object per step, and the event is fired if (and only if) a collision is detected. In this case, you can change the scope to that instance's viewpoint via
other. In fact, if you used the code snippet above in a Step event,
_inst works exactly the same as
other works in a Collision event. This means that you can prefix a variable with
other.variable and access the variable of the instance you're colliding with. You can also fully switch the scope to the instance you're colliding with via
with (other).
For the sake of completeness: The other case (no pun intended) where you can use
other is inside of a
with statement. Here, it refers to the instance that originally executed the
with statement, so it can be used to change the scope
back to the default after having changed it with a
with statement.