repeating_timer.gui_script 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. -- set value of numeric time indicator (from 0 to 60s)
  2. local function update_numeric(p)
  3. local node = gui.get_node("numeric")
  4. gui.set_text(node, tostring(p) .. "s")
  5. end
  6. -- update radial/circle time indicator by changing the fill angle
  7. local function update_radial(p)
  8. local node = gui.get_node("radial")
  9. local angle = p * 6
  10. gui.set_fill_angle(node, angle)
  11. end
  12. function init(self)
  13. self.count = 0 -- <1>
  14. local interval = 1 -- <2>
  15. local repeating = true -- <3>
  16. timer.delay(interval, repeating, function() -- <4>
  17. self.count = self.count + 1 -- <5>
  18. local p = self.count % 60 -- <6>
  19. update_numeric(p) -- <7>
  20. update_radial(p) -- <8>
  21. end)
  22. end
  23. --[[
  24. 1. Start the count with value 0.
  25. 2. We will use interval of 1 [s].
  26. 3. We will be repeating the timer endlessly.
  27. 4. Start the timer with interval (1s) and repeating (true) and pass a callback function.
  28. 5. The function will be called every 1s, so increase the count by 1 each time.
  29. 6. Get the modulo of 60, because the timer will be reset every 60s.
  30. 7. Update the numeric display of seconds passed.
  31. 8. Update the radial indicator of seconds passed.
  32. --]]