Thanks for the response! The towers never move, but the crystals do (the player character will be able to pick them up and move them).
When the player picks up a gem/crystal, does the instance get destroyed or does it teleport to the player?
I tried using the If Collision Shape action and that part works, but after that I'm trying to assign a variable to the tower that triggered the If Collision Shape and I'm having trouble with that. I thought I'd be able to do an Assign Variable to "Other" but that doesn't seem to work. I recently read up on how the "Other" option works and to my understanding when Other is used during a collision event, it applies itself to the object that triggered the collision. Maybe I'm misunderstanding how "Other" works? Or am I just not executing it correctly?
That's kind of how the "other" keyword works, but there's more to it.
First of all, you are right in that the collision event makes the other keyword refer to the instance that is colliding with the executing instance and triggered the event as a result.
However, you are not using the collision event, you're using the "If Collision Shape" action, which does not alter what "other" refers to.
Now, the keyword other actually has a different meaning.
In GameMaker, you have a
with-construction, with a corresponding "
Apply To..." action.
With this construction/action, you can tell some instance A to make some instance B perform some specific code.
In the body of this construction/action, you won't be using the instance scope of instance A anymore, but the instance scope of instance B.
This means that when you refer to variables for example, you will be referring to the variables of instance B and not those of instance A, as you would outside the body.
You will often still need to refer to variables of instance A from inside a with-construction / "Apply To..." action however and this is where the "other" keyword comes into play.
Within the body of a with-construction / "Apply To..." action, the "other" keyword refers to the instance that called the construction/action (instance A).
Outside of a with-construction / "Apply To..." action, the "other" keyword will refer to:
1) the other instance involved in a collision when inside a collision event
2) the executing instance (self) otherwise
The way I like to think of this however, is that GameMaker calls collision events of objectA with objectB as follows:
GML:
// This gets executed at the end of the step event in objectA
with objectB { // We now make instances of objectB execute some code
if place_meeting(x, y, other) { // If the current objectB instance overlaps with "other", which refers to the objectA instance
with other { // Then make the objectA instance execute some code
event_perform(ev_collision, objectB); // Perform the collision event where "other" now refers to the overlapping objectB instance
}
}
}
This view unifies the interpretation of the "other" keyword in with-constructions / "Apply To..." actions with the interpretation of the other keyword in collision events.
Anyway, that's some background on the topic of the "other" keyword, but it isn't super relevant to your current issue.
Here's some images of my program. First two pics are the tower, and the last one's the gem (or crystal. Haven't decided on a name yet lol). Idk if this is the best way to do this, but as you can see I assigned a variable to the tower called gem_range which will act as a true or false variable (1 meaning true, and 0 false). I want the gem to change that variable in the tower to 1 when it comes in range (and back to 0 when it goes out of range but I'll figure that out later), so I have an Assign Variable action in the gem set to Other which doesn't seem to be working. From looking at this can you see anything I'm doing wrong?
Knowing now that the "other" keyword won't work, you'll have to follow the example in the docs about the "
If Collision Shape" action more closely.
They have "Return List" checked and have "inst_list" as "Target".
As the docs explain, this makes the action store all the colliding instances (towers) inside a ds_list inside the variable inst_list.
In the example, they then loop through every instance (tower) in the list.
For each tower, they then use an "Apply To..." action to assign a value to a variable of the (tower) instance currently being iterated over.
At the end, they also clean up the ds_list, which you should do too in order to avoid memory leaks.