Jump to content

getTime condition


off

Recommended Posts

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

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: 

  1. timehour, timeminute = getTime()
  2. debounce = false
  3. var = 0
  4.  
  5. if timehour == 12 and timeminute == 0 and debounce == false then
    1. var = var + 1 --I want to execute this line only once whenever the condition is true
    2. debounce = true
  6. end

Hope this helps!

 

  • Thanks 1
Link to comment
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: 

  1. timehour, timeminute = getTime()
  2. debounce = false
  3. var = 0
  4.  
  5. if timehour == 12 and timeminute == 0 and debounce == false then
    1. var = var + 1 --I want to execute this line only once whenever the condition is true
    2. debounce = true
  6. 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...