Skip to content

Instantly share code, notes, and snippets.

@katsaii
Last active November 3, 2019 09:43
Show Gist options
  • Save katsaii/1ed55debd0c0c7be02a78a0c464b50ee to your computer and use it in GitHub Desktop.
Save katsaii/1ed55debd0c0c7be02a78a0c464b50ee to your computer and use it in GitHub Desktop.
A hack which finds the index of the current calling script.
/// @desc Returns the id of the current script.
/// @author Kat @katsaii
var callstack = debug_get_callstack();
var header = "gml_Script_";
var delimiter = ":";
for (var i = 1; i < array_length_1d(callstack); i++) {
var currentTrace = callstack[i];
if (string_pos(header, currentTrace) == 1) {
var name = string_replace(currentTrace, header, "");
var length = string_pos(delimiter, name);
if (length > 0) then name = string_copy(name, 1, length - 1);
if (asset_get_type(name) == asset_script) then
return asset_get_index(name);
}
}
return -1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment