I’ve noticed in several scripts that people either define debounce as either this
db = <boolean>
or this
debounce = <boolean>
My question is that what’s the difference between using db or debounce?
If they’re the same, then why would people use db instead of debounce and vice versa?
Both are variables which could be named as anything they’d like. But of course, naming convention is important when programming so it’s easiest to understand and read.
As to why one would put db or debounce, that’s completely up to preference. I personally switch between the two, just based on how I feel .
Some more examples of this would be how some people name Services :
local defines the scope in which the variable can be used.
local deb = false
function aFunction()
local deb_2 = false
deb_3 = false
end
print(deb) -- false
print(deb_2) -- error
print(deb_3) -- false
Variables not defined as local are instead global. This helps when working with different variables, but with the same name.
deb = 2
function aFunction()
local deb = false
print(deb) -- false
end
function anotherFunction()
local deb = "AString"
print(deb) -- "AString"
end
print(deb) -- 2