Last active
November 3, 2019 09:43
-
-
Save katsaii/1ed55debd0c0c7be02a78a0c464b50ee to your computer and use it in GitHub Desktop.
A hack which finds the index of the current calling script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// @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