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

How to make a function not stack on itself?

Asked by 10 years ago

Please include the code which you are trying to use, so the community will be better-equipped to help you with your problem.

I have a singular function, but whenever that function activates, the same function can be activated again. How do I prevent the function from happening, whilst the same function is functioning

example: I stand next to a sensor with the door, but since I'm standing with the sensor, the door slams me in the face and opens until I'm not in the sensor.

2 answers

Log in to vote
2
Answered by
duckwit 1404 Moderation Voter
10 years ago

A debounce is a boolean flag that you use to keep track of when the function is active and when it is not, implemented as such:

debounce = false

function YourFunction()
if not debounce then 
debounce = true
--Do your stuff
debounce = false
end
end
Ad
Log in to vote
2
Answered by
Cizox 80
10 years ago

Add a debounce to the function, so the function will only run after it has been completely executed, or in your case, it will only run after you step off the sensor.

Answer this question