Call a gml Function - coldrockgames/doc-scriptor GitHub Wiki
GameMaker lacks functionality to directly call built-in functions using their names, which can make "reflection-like" tasks challenging. Since there's no way to directly retrieve a function pointer for built-ins, we must use a translation dictionary to map function names to their corresponding implementations.
For example, if you want to call functions like array_push
or asset_get_index
in a Scriptor
script, this translation dictionary bridges the gap.
The ScriptorGml
script, located in the gml-scriptor
folder of your project, serves as this translation dictionary.
It maps string representations of function names to their respective GML functions.
The ScriptorGml
script includes a set of commonly used GML functions. However, this list is not exhaustive. If you need additional functions, you can easily extend the list by adding them to the script.
Note
Make sure the string representation of your function includes the gml
prefix. Without this prefix, Scriptor will not recognize the function.
Here's the content of ScriptorGml
at the time of writing this documentation:
/*
Creates an array with all supported native gml functions in scriptor.
To add a new function, simply include it in the list below.
IMPORTANT:
- KEEP THIS LIST SORTED ALPHABETICALLY to make it easier to find entries.
- USE the "gml_" prefix in the string keys. In your scripts, call functions
by their original names (e.g., `array_push(...)`, NOT `gml_array_push(...)`).
*/
function ScriptorGmlExecutor() {
return {
"gml_array_pop" : array_pop,
"gml_array_push" : array_push,
"gml_array_shift" : array_shift,
"gml_array_get" : array_get,
"gml_array_set" : array_set,
"gml_array_first" : array_first,
"gml_array_last" : array_last,
"gml_array_length" : array_length,
"gml_asset_get_index" : asset_get_index,
"gml_ceil" : ceil,
"gml_choose" : choose,
"gml_clamp" : clamp,
"gml_cos" : cos,
"gml_dcos" : dcos,
"gml_degtorad" : degtorad,
"gml_dsin" : dsin,
"gml_dtan" : dtan,
"gml_floor" : floor,
"gml_instance_destroy" : instance_destroy,
"gml_int64" : int64,
"gml_irandom_range" : irandom_range,
"gml_min" : min,
"gml_max" : max,
"gml_object_get_name" : object_get_name,
"gml_point_distance" : point_distance,
"gml_point_direction" : point_direction,
"gml_point_in_circle" : point_in_circle,
"gml_point_in_triangle" : point_in_triangle,
"gml_point_in_rectangle" : point_in_rectangle,
"gml_radtodeg" : radtodeg,
"gml_random_range" : random_range,
"gml_real" : real,
"gml_script_exists" : script_exists,
"gml_show_debug_message" : show_debug_message
"gml_sin" : sin,
"gml_string" : string,
"gml_string_split" : string_split,
"gml_string_split_ext" : string_split_ext,
"gml_string_concat" : string_concat,
"gml_string_upper" : string_upper,
"gml_string_lower" : string_lower,
"gml_string_trim" : string_trim,
"gml_string_trim_end" : string_trim_end,
"gml_string_trim_start" : string_trim_start,
"gml_struct_get" : struct_get,
"gml_struct_set" : struct_set,
"gml_struct_exists" : struct_exists,
"gml_struct_remove" : struct_remove,
"gml_struct_get_names" : struct_get_names,
"gml_tan" : tan,
};
}