Timer Toggle

KresslackKresslack Florida, United States
edited May 2013 in Tech Support
How would one go about making a toggable tigger, which is turned on and off using an alias, such as TN | TF? Any help would be greatly appreciated. 




Misspelled titles make me cry.


Comments

  • JonathinJonathin Retired in a hole.
    edited May 2013
    Instead of having the timer run indefinitely, you could always use enable/disableTimer()

    Alternatively, if you don't want to use a variable you can use isActive().

    Example:

    if isActive("timerName","timer") == 1 then  --1 because isActive returns as 0 or 1
      disableTimer("timerName")
      echo("timerName disabled!")
    else
     enableTimer("timerName")
     echo("timerName enabled!")
    end
    I am retired and log into the forums maybe once every 2 months. It was a good 20 years, live your best lives, friends.
  • Daeir said:
    Does lua evaluate 0/1 as true/false like other C languages? A bit unrelated, but you should just be able to use isActive without the equals evaluation.
    Lua evaluates false and nil as false and anything else (including 0) as true.
  • Yeah. isActive() actually returns a count of active aliases/triggers/timers by that name, not a boolean value. It would return 2 if you had two timers by that name.
  • JonathinJonathin Retired in a hole.
    My bad. I don't have more than 1 of anything with a particular name, so it's always returned 0 or 1 for me. Good to know though.
    I am retired and log into the forums maybe once every 2 months. It was a good 20 years, live your best lives, friends.
  • KresslackKresslack Florida, United States
    Completely forgot about this, but thanks for all the advice. About to try it out.


Sign In or Register to comment.