So I was looking at Sceleratis's Addonis Core and he starts off with:
01 | local _G = _G |
02 | local script = script |
03 | local game = game |
04 | local workspace = workspace |
05 | local getfenv = getfenv |
06 | local setfenv = setfenv |
07 | local getmetatable = getmetatable |
08 | local setmetatable = setmetatable |
09 | local math = math |
10 | local print = print |
11 | local warn = warn |
12 | local error = error |
13 | local coroutine = coroutine |
14 | local pcall = pcall |
15 | local ypcall = ypcall |
Is there any reason for this/does it do anything?
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?
For those of scripters who are anal about performance, a useful piece of information is that global variables are about 10x slower for each access than local variables. When you're running stuff in tight loops, or as an addon, that sort of stuff stacks up.
There's also the upvalues argument. Occasionally I will (for example) insert all of the values I'm using into locals ahead of time because then they are accessed by functions as upvalues instead of fetching them from the global environment. This avoids variable value inconsistency, as you can expect each variable to point to what it was defined as (For more information on environments, look here and refer to 5.1)
So, to those of you who thought it's for nothing, now you know better.
The most reasonable reason would be that it would be easier to target them or hes just lazy so he made them the same variable but in a easier way since roblox doesnt target it or auto complete it so he made those variables so roblox does target it.