kemonologic

script_called

Dec 1st, 2019 (edited)
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// @func script_called
  2. /// @arg {bool*} includeLineNum
  3. /// @desc Returns the name of the last script called, can thus be used like id but for scripts
  4.  
  5. var _includeLineNum = true;
  6. if (argument_count > 0) {
  7.     _includeLineNum = argument[0];
  8. }
  9.  
  10. var _callStackArr = debug_get_callstack();
  11. var _excludedScripts = ds_list_create();
  12.  
  13. // Add scripts to exclude here
  14. ds_list_add(_excludedScripts, "script_called", "fTrace", "show_debug_message");
  15.  
  16. for (var i = 0; i < array_length_1d(_callStackArr); i++) {
  17.     var _wasExcluded = false;
  18.     var _scr = _callStackArr[i];
  19.     var _scrNice = string_replace(_scr, "gml_Script_", "");
  20.     _scrNice = string_replace(_scrNice, "gml_Object_", "");
  21.     var _scrStrLen = string_length(_scrNice);
  22.     var _scrLineNumIndex = string_pos(":", _scrNice);
  23.     var _scrNoLineNum = string_delete(_scrNice, _scrLineNumIndex, _scrStrLen - _scrLineNumIndex + 1);
  24.     _wasExcluded = (ds_list_find_index(_excludedScripts, _scrNoLineNum) != -1);
  25.     if (!_wasExcluded) {
  26.         ds_list_destroy(_excludedScripts);
  27.         return _includeLineNum ? _scrNice : _scrNoLineNum;
  28.     }
  29. }
  30.  
  31. ds_list_destroy(_excludedScripts);
Add Comment
Please, Sign In to add comment