off Posted August 19, 2018 Share Posted August 19, 2018 How I run the line only once, until the condition is true again? timehour, timeminute = getTime() var = 0 if timehour == 12 and timeminute == 0 then var = var + 1 --I want to execute this line only once whenever the condition is true end Apparently the line runs more than once during the time of the condition. Link to comment
Discord Moderators Pirulax Posted August 20, 2018 Discord Moderators Share Posted August 20, 2018 That's physically impossible. Why would it run more than once? Link to comment
Crossy101 Posted August 20, 2018 Share Posted August 20, 2018 Nope it will run a couple of times if it's either inside a loop or gets called again within a short amount of time the best thing to do is add some kind of boolean variable. Example: timehour, timeminute = getTime() debounce = false var = 0 if timehour == 12 and timeminute == 0 and debounce == false then var = var + 1 --I want to execute this line only once whenever the condition is true debounce = true end Hope this helps! 1 Link to comment
Discord Moderators Pirulax Posted August 20, 2018 Discord Moderators Share Posted August 20, 2018 Please remove that background color, or whatever is that, because it's ugly like this. So. He haven't said that it's in a loop, he just gave us a code with an 'if' statement. Link to comment
Crossy101 Posted August 20, 2018 Share Posted August 20, 2018 (edited) Well exactly you have figured out the problem, if it's not in a loop it's being called multiple times. One thing you should really learn to do is brighten up that attitude. Edited August 20, 2018 by Crossy101 1 Link to comment
Discord Moderators Pirulax Posted August 20, 2018 Discord Moderators Share Posted August 20, 2018 Quote more than once during the time of the condition. Link to comment
Crossy101 Posted August 20, 2018 Share Posted August 20, 2018 You do understand it can be 12:00 for more than a few seconds right?? Just like real life! Link to comment
off Posted August 20, 2018 Author Share Posted August 20, 2018 3 hours ago, Crossy101 said: Nope it will run a couple of times if it's either inside a loop or gets called again within a short amount of time the best thing to do is add some kind of boolean variable. Example: timehour, timeminute = getTime() debounce = false var = 0 if timehour == 12 and timeminute == 0 and debounce == false then var = var + 1 --I want to execute this line only once whenever the condition is true debounce = true end Hope this helps! Thank you! By your logic, Ive added another conditional so that the line is executed again when it reaches the condition. Look: timehour, timeminute = getTime() debounce = false var = 0 if timehour == 12 and timeminute == 0 and debounce == false then var = var + 1 --I want to execute this line only once whenever the condition is true debounce = true elseif timehour ~= 12 and timeminute ~= 0 and debounce == true then debounce = false end Incredibly just with 'else', I went back to the previous problem. Determining exactly the conditions, as I did by your logic, it works perfectly! Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now