

While not exactly variables, macros are similar to them in how they are used, i.e.: they are named values that you can use throughout your code to replace hard-coded values. These are outlined on the appropriate pages for the runtime functions that require them in the GML Reference section. NOTE The GameMaker Language also has a number of built-in constant values that are used to identify specific things. Also note that any value that is always the same is classed as a constant, regardless of the data type, for example, a string or the number 3. In the GameMaker Language there are two types of user-defined constant: macros and enums, both of which are explained below.

This makes them ideal for holding values that are used throughout the game to identify special data. In fact, constant values cannot be changed after they have been declared. A constant is a type of variable that is set once at the start of the game and then never changes. This approach also shows promise in reducing potential bugs by hiding the job of synchronising global variables with expected inputs to built-in functions. This post has discussed an interesting undocumented feature of macros, and how it can be used to fill gaps within the GameMaker standard library. This can help reduce the likelihood of bugs related to system objects from occurring. An example of this is shown in Figure 1.Īlso included in the repository is a singleton system, which overrides the built-in instance functions in order to prevent multiple singletons of the same type from being created, and to offer deactivation immunity to system objects. In conjunction with application_set_position_fixed, these extensions allow for low-resolution games to scale "pixel-perfectly," whilst also enabling a high-resolution GUI. Most importantly, display_set_gui_position lifts a restriction of the current GUI functions, requiring that either the offset or scale of the GUI could be set, but not both simultaneously 2. network_get_config - Enables getting network configurations set by the user.Īll extensions have seen practical use in projects I've been a part of.display_set_gui_position - Enables setting an exact region and scale to draw the GUI in.application_set_position_fixed - Similar to application_set_position, except preserving aspect ratio.application_set_position - Enables setting an exact region to render the application surface.A list of functions that have been implemented include: Pixel-perfect scaling with a high-resolution GUI layerĪ few experiments can be found on GitHub that extend the GameMaker standard library. This further increases the effort required to make a mistake when using the library. Note: since many auto-complete engines order underscores after letters alphabetically, any identifiers starting with an underscore will usually appear at the end of the list. Similarly, this could be applied to the macro definitions and function overides in order to coerce users into only using the getter and setter functions. This essentially reduces the likelihood of a team member making a mistake, by increasing the effort required to type out the names of protected global variables.

Since getter functions return a copy of the values stored in the global variables, there is no risk of accidentally modifying them, and hence desynchronising their values. windowMinHeight = - 1 function set_min_size ( width, height ) The following example illustrates how such an approach could be applied: global.

These global variables could then be accessed in order to obtain the current window size. One method to circumvent this would be to maintain a set of global variables ones that would store the current minimum and maximum size of the window. This is typically due to the low-priority of niche functionality for instance, there exists functions for setting the minimum and maximum size of the game window 1, but (currently) no functions for getting these values back in case they were updated somewhere else in the codebase. Like many libraries, there are gaps in the set of built-in functions provided by GameMaker. Since this feature is undocumented, it wouldn't be wise to depend entirely on any topics discussed throughout this post, in case something changes in the future or there are inconsistencies between target platforms. This post goes into detail about an undocumented feature of GML, originally brought to my attention by Zach Reedy. By exploiting an undocumented feature of macros in GameMaker Language (GML), calls to standard library functions can be intercepted in order to help implement missing features.
