Making a debounce function with the callback, i need to figure out how to actually get the variable name.
function DebounceBool(boolvar,bool,callback)
local boolvariable = boolvar -- this thing actually says value
-- instead of the variable itself
repeat
callback()
print(tostring(boolvariable)..' Debounced')
until boolvariable == bool
boolvariable = bool
end
You can show the full script? or the script that calls that function?
I recommend to do another variable to the function called “boolname” so something like that, that variable storages the variable name
s = {'bool1',true}
local env = getfenv(0)
for k, v in pairs(env) do
if type(v) == 'table' then
if v[1] == 'bool1' then
print(k..' = '..tostring(v[2]))
end
end
end
-- s = true
This is true, optimizations such as inline caching and global access chains are disabled for functions that have had their environments read/written, additionally, the loadstring global function will disable these optimizations. This deoptimization process can be mitigated by declaring globals as upvalues (non-local variables) to functions that have their environments read/written.
local Print = print --Integrate 'print' global function into local environment.
local Pairs = pairs
String = "Hello world!"
local env = getfenv(0)
for k, v in Pairs(env) do
if v == "Hello world!" then Print(k) break end --'String' is output.
end
It should be noted that these optimizations are insignificant in the grand scheme of things.