GMS 2 how to get a constant name?

Suzaku

Member
I have a enumerator with some constants inside, and I would like to show their names in my console, not their values, something like

show_debug_message(getConstantName(parameterHere));

Is that possible? Thank you.
 

FrostyCat

Member
No, the name is translated away during the build process. You have to specify the result explicitly.

If you didn't set explicit values to any of the enum entries, you can do something like this:
Code:
enum ENUM {
  FOO,
  BAR,
  BAZ
}
#macro ENUM_NAME global.ENUM_NAME
gml_pragma("global", @'global.ENUM_NAME = [
  "FOO",
  "BAR",
  "BAZ"
];');
Code:
show_debug_message(ENUM_NAME[parameterHere]);
If you did set explicit values to one or more enum entries, you can do something similar with maps instead of arrays.
Code:
enum ENUM {
  FOO = 123,
  BAR = 456,
  BAZ = -789
}
#macro ENUM_NAME global.ENUM_NAME
gml_pragma("global", @'
  global.ENUM_NAME = ds_map_create();
  global.ENUM_NAME[? 123] = "FOO";
  global.ENUM_NAME[? 456] = "BAR";
  global.ENUM_NAME[? -789] = "BAZ";
');
Code:
show_debug_message(ENUM_NAME[? parameterHere]);
 
Top