How do I change a variable of other objects in Game Maker from a different object?
Answer:
Usually, you'll want to change an objects variable from that same object during the game. But sometimes you might want to change another object's variable from a different object. Here's how you do it:
Let's say we have two objects: objPlayer and objScore. Let's say objScore has a variable theScore. And let's also say that when objPlayer collides with something, we want to change the score variable in objScore.
In the collision event of the objPlayer with the other object, execute this code:
objScore.theScore += 1; |
This code will add 1 to the score when the objPlayer collides with something! Just put the objects name, a period, then the variable name. Epic!
Page updated: March 23rd, 2015 @ 6:21 AM Eastern Time |