Last active
September 20, 2019 19:45
-
-
Save katsaii/7b4785d68e2689e5e66741681b7df083 to your computer and use it in GitHub Desktop.
Pseudo properties using macros in GameMaker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#macro VAR "foo" | |
#macro GETTER variable_global_get(VAR) | |
#macro SETTER \ | |
for (var __value = GETTER;; { \ | |
if (is_real(__value) && __value > 0) { \ | |
variable_global_set(VAR, __value); \ | |
} else { \ | |
show_error("Global property '" + VAR + "' must be a positive number", false); \ | |
} \ | |
break; \ | |
}) __value |
You may also be able to create a getter-setter using the macro:
#macro GETSET GETTER; SETTER
with the limitation of not being able to use it 'inline' like the original getter.
In other words, the following is invalid code:
GETSET = 3;
show_message(GETSET); // invalid token
since the macro GETSET
will be transformed into:
GETTER; SETTER = 3;
show_message(GETTER; SETTER); // invalid token
which is obviously invalid.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Examples
Getting and setting:
Setting an invalid value:
Using the addition assignment operator on the property: