nameof

This function returns the name of the argument you pass to it as a string.

More precisely, this function returns the name of the identifier that you pass to it; any name to identify something used in your GML code: an asset name, a variable name, a function name, an enum name, ...

GameMaker resolves the values when Compiling the game, i.e. at compile time.

NOTE You cannot use this function to get the name of Macros or members of Enums; in this case GameMaker respectively returns the name of what the macro refers to or the internal value of the enum member.

 

Syntax:

nameof(name);

ArgumentTypeDescription
nameAnyThe variable of which to get the name

 

Returns:

String

 

Example:

show_debug_message("About to reveal internal names...");

show_debug_message($"The enemy object is called: {nameof(obj_enemy)}");
show_debug_message($"{pi} is a special value, it is called {nameof(pi)}.");
show_debug_message($"The function to create a ds_list is called: {nameof(ds_list_create)}, or even: {nameof(ds_list_create())}");

var _a = 77, _b = 66;
var _c = _a + _b;
show_debug_message($"The sum of {nameof(_a)} and {nameof(_b)} is {nameof(_c)}, or, using their values: {_a} + {_b} = {_c}");

The code above shows a few examples on how to use the nameof function. The name of various variables and functions in GML is looked up using the function and output in the debug log using show_debug_message.