Question:
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
Game Making Tutorials
Find tutorials about your favorite game creation software! Use the navigation below!

Game Maker: Studio
Help, References, and Tutorials
RPG Maker Fes
Help, References, and Tutorials
smileBASIC
Help, References, and Tutorials

Need Help?
Search answers to game development questions or ask a question yourself
Get exclusive updates from ExecuteCode.com!
Join the Email List
Download Books
Search Downloadable Books from ExecuteCode.com
Copyright 2010-2018 ExecuteCode.com.
All Rights Reserved.