So recently I’ve been having a troubling time deciding on how to add debounce to my functions. These two functions do the same thing; I’m just worried there might be something I’m missing, like: Is the second function just better practice? Can return mess something up?
local debounce = false
local function foo()
if debounce then
return
end
debounce = true
-- code stuff
debounce = false
end
-- somewhere else
local debounce = false
local function foo()
if not debounce then
debounce = true
-- code stuff
debounce = false
end
end
This is kind of a stupid question, but it’s been itching at me lately. Any help is appreciated
Both do the same thing and either is acceptable its just a matter of how you, the coder, likes to style your code. Some people like to put their conditions at the top of a function with a return included some like to put their code within the if condition. All up to you and no return won’t mess anything up.