• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Get the script name within the script?

FacesOfMu

Member
I see there's script_get_name(scr), but that requires the input of the script index. Is there anyway to get the name of the script the code is in without knowing the index?
For example, objects have the "self" and "id" keywords to reference themselves. I'm looking for a programmatic way to refer to it (for a debug message code snippet).
 

sixonekevin

Member
Curious if there are better solutions with the most recent runtimes.
Doubtful since script names are even less relevant now than they were in 2019 due to the GMS2.3 update in 2021 that made it so scripts and functions no longer have a 1:1 relationship.
 

kraifpatrik

(edited)
GameMaker Dev.
This one works with functions:

GML:
/// @func bbmod_get_calling_function_name()
///
/// @desc Retrieves name of the calling function.
///
/// @return {String} The name of the calling function.
function bbmod_get_calling_function_name()
{
    gml_pragma("forceinline");
    var _name = debug_get_callstack(/*2*/)[1]; // TODO: Check if this argument works in YYC already
    _name = string_replace(_name, "gml_Script_", "");
    var _pos = string_pos(":", _name);
    if (_pos > 0)
    {
        _name = string_copy(_name, 1, _pos - 1);
    }
    return _name;
}
EDIT: Maybe you find it useful. Example:

GML:
function do_some_stuff()
{
    // Prints string "do_some_stuff"
    show_debug_message(bbmod_get_calling_function_name());
}
 

Yal

šŸ§ *penguin noises*
GMC Elder
I've noticed the word script gets the same color highlighting as other built-in variables, what's the output of script_get_name(script)?
(Checked the manual and it doesn't show up in the index so it appears to be undocumented, but in fairness it's also a very generic word so it's easy to overlook)
 

Evanski

Raccoon Lord
Forum Staff
Moderator
what's the output of script_get_name(script)?
GML:
Variable <unknown_object>.script(100003, -2147483648) not set before reading it.
I think script is one of those black box built in things

I'm curious as what situation would you not be trying to get the name of the script thats running Outside of the script?
because I'm pretty sure you'd try to figure out what script is running in the scope of itself in which case script_get_name( name_of_script_asset_that_you_are_writing_this_in) would work just fine
 
Top