Add an exception to a variable for only one instance

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By PotatoPro

If i have a ton of instances, each having a default variable value, how can i make an exception for a few of them?

Imagine a button with a default state = OFF.
Say i have 100 buttons on screen. But i want 3 of them to be in the ON state.

In GameMaker Studio it’s possible to add a “creation code” for specific instances. Very useful to override default variable values.

How are you adding the button; in code or in the editor?

SteveSmith | 2023-02-20 14:37

In the editor

PotatoPro | 2023-02-20 14:41

:bust_in_silhouette: Reply From: SteveSmith

Add a script to the buttons so you can export a default state. Then in the ready() method, set the button’s state to this default state.

Works great!

Do i have to attach a script to every single instance i want to change in the editor?

PotatoPro | 2023-02-20 16:33

I’d create a new button scene that extends Button, and attach the script to it. Then use that button scene as the template when creating new buttons.

SteveSmith | 2023-02-20 18:25