How do I use these debug functions

Sorry if I’m late to this, don’t know when these came out, but how do I use these debug functions?

debug.info
debug.resetmemorycategory
debug.setmemorycategory

setmemorycategory sets the name the script will show up as in the F9 menu memory tab under placescriptmenu

debug.setmemorycategory("epic")

image

resetmemorycategory just resets the memory category to the default

debug.info on the other hand does a ton of weird stuff

function testFunction(a,b,c,d)
    return a,b,c,d
end

local numArgs = debug.info(testFunction,"a") --seems to return number of arguments
              --           and a boolean describing if it has ... in its arguments
local func = debug.info(testFunction,"f") --seems to return just the function itself
local idek = debug.info(testFunction,"i") --I have no clue what this does
local whatInTheWorld = debug.info(testFunction,"n") --seems to print the name of the function
local bruh = debug.info(testFunction,"s") --seems to print the contents of the function or something

It also appears as if you can combine them into a series of things

local numArgsAndFunc = debug.info(testFunction,"af") --returns both the number of arg stuff and the function

It also appears that you can use a number to get stuff describing the current environment

function test(a,b,c)
    print(debug.info(1,"a")) --prints the number of arguments of "test"
end
function test1(a,b,c)
    function test2(a,b,c)
         print(debug.info(1,"a")) --prints the # of arguments of "test2" (2 functions up from current environment)
         print(debug.info(2,"a")) --prints the # of arguments of "test1" (1 function up from current environment)
    end
end

Kinda weird how this isnt documented anywhere, roblox will probably announce something about it sometime

14 Likes

Thank you!!

Also after doing some research, s parameter prints the source of the function (or like calling :GetFullName() on the script that holds the function)

print(debug.info(CoolRandomFunction,"s")) -- prints Workspace.Script
4 Likes