Guest User

Untitled

a guest
Jan 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. -- An example for using Timer class to chain functions together
  2. -- (letting you insert delay between parts)
  3. -- Little bit simplified for verbosity
  4.  
  5. -- First function to fire
  6. function SetupPartOne()
  7. print('Do the first thing here')
  8.  
  9. -- Next function after 5 seconds
  10. CreateOneshotTimer('SetupPartTwo', 5)
  11. end
  12.  
  13. -- Second function to fire
  14. function SetupPartTwo()
  15. print('Next thing')
  16.  
  17. -- Next function after 12 seconds
  18. CreateOneshotTimer('SetupPartThree', 12)
  19. end
  20.  
  21. -- Last function to fire
  22. function SetupPartThree()
  23. print('And so on, you get the idea')
  24. end
  25.  
  26. -- Helper function for creating timers
  27. function CreateOneshotTimer(fcnName, delay)
  28. Timer.create({
  29. identifier = tostring({}), -- unique name
  30. function_name = fcnName, -- what it triggers
  31. function_owner = self,
  32. delay = delay, -- delay in seconds
  33. repetitions = 1, -- oneshot
  34. })
  35. end
  36.  
  37. -- We'll be starting setup on load
  38. function onLoad()
  39. -- Start the first one whenever to fire off the chain
  40. SetupPartOne()
  41. end
Add Comment
Please, Sign In to add comment