Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Using _G Functions help?

Asked by
iLegitus 130
8 years ago

So i've made a global function,So i want this function to basically print out the name of the script that ran it. Such as,If the script "LolHax" accessed the function,The function would print out the script that used it (In this case LolHax),And not print out the name of the script its located in.

Help much appriciated.

1 answer

Log in to vote
1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

Say you have a script named a:

_G.var=function()
    print(script.Name)
end
_G.var()

and a script named b:

wait()
_G.var()

This will print "a" twice. If you want to get the script that the function is called from, you need to access its function environment, so a becomes

_G.var=function()
    print(getfenv(0)["script"].Name)
end
_G.var()
Ad

Answer this question