Advertisement
perazite

Timer Fuction

Nov 9th, 2016
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Function - Timer
  2. ; Fanatic Guru
  3. ; 2013 06 20
  4. ;
  5. ; Function to Create and Manage Timers
  6. ;
  7. ;------------------------------------------------
  8. ;
  9. ; Method:
  10. ;   Timer(Name of Timer, Options)
  11. ;   All times are in milliseconds and use A_TickCount which is milliseconds since computer boot up
  12. ;
  13. ;   Parameters:
  14. ;   1) {Name of Timer} A Unique Name for Timer to Create or Get Information About
  15. ;   2) {Option = {Number}} Length of Timer
  16. ;      {Option = D or DONE} Return true or false if timer is done and period has passed
  17. ;      {Option = S or START} Return start time of timer
  18. ;      {Option = F or FINISH} Return finish time of timer
  19. ;      {Option = L or LEFT} Return time left of timer, will return a negative number if timer is done
  20. ;      {Option = N or NOW} Return time now
  21. ;      {Option = P or PERIOD} Return period of timer ie. duration, span, length
  22. ;      Optional, Default = "D"
  23. ;
  24. ; Returns:
  25. ;   Creates or Returns Information About Timer Based on Options
  26. ;   Timer() refreshes all timers which updates the information in the Timer array
  27. ;
  28. ; Global:
  29. ;   Timer.{Timer Name}.Start|Finish|Period|Done|Left|Now
  30. ;     Creates a global array called Timer that contains all the timer information at the time of last function call
  31. ;   To use a variable to retrieve Timer information use [] array syntax
  32. ;     Timer[Variable_Name,"Left"]
  33. ;   Timer_Count = number of Timers created
  34. ;   Variables contain the information the last time function was called
  35. ;   To obtain current information either call the Timer specifically by Name of Timer or use Timer() to update all variables
  36. ;
  37. ; Examples:
  38. ;   Timer("Cooldown",8000)  ; <-- Creates a Timer named Cooldown with an 8 second period
  39. ;   Timer("Cooldown")   ; <-- Returns True if Timer is Done, False if not Done
  40. ;   Timer("Cooldown,"L")  ; <-- Returns updated time Left on Timer
  41. ;   Timer(VariableName,30000)  ; <-- Creates A Timer named the contents of VariableName with a 30 second period
  42. ;
  43. ;   When Name of Timer = Cooldown
  44. ;   Timer.Cooldown.Period  ; <-- Variable created by Function that contains Period (Duration) of Timer named Cooldown
  45. ;   Timer.Cooldown.Start  ; <-- Variable created by Function that contains internal clock time when Timer Started
  46. ;   Timer.Cooldown.Finish  ; <-- Variable created by Function that contains internal clock time when Timer will Finish
  47. ;   Timer.Cooldown.Now   ; <-- Variable created by Function that contains internal clock time last time function was called
  48. ;   Timer.Cooldown.Done   ; <-- Variable created by Function that contains Done status last time function was called
  49. ;   Timer.Cooldown.Left   ; <-- Variable created by Function that contains time Left last time function was called
  50. ;   Timer["Cooldown","Period"]  ; <-- Equivalent to above . array syntax but works better if using Variable to replace literal strings
  51. ;
  52. ;   For index, element in Timer  ; <-- Useful for accessing information for all timers stored in the array Timer
  53. ;
  54. ; It is important to understand that () are used to call the function and [] are used to access global variables created by function
  55. ; The function can be used for many applications without ever accessing the variable information
  56. ; I find it useful to have access to these variables outside the function so made them Global but they could probably be made Static
  57. ;
  58. Timer(Timer_Name := "", Timer_Opt := "D")
  59. {
  60.  static
  61.  global Timer, Timer_Count
  62.  if RegExMatch(Timer_Opt,"(\d+)",Timer_Match)
  63.   Timer_Period := Timer_Match1
  64.  else
  65.   Timer_Period := 0
  66.  if RegExMatch(Timer_Opt,"(\D+)",Timer_Match)
  67.   Timer_Opt := Timer_Match1
  68.  else
  69.   Timer_Opt := "D"
  70.  if !Timer
  71.   Timer := {}
  72.  if (Timer_Name = "")
  73.  {
  74.   for index, element in Timer
  75.    Timer(index)
  76.   return
  77.  }
  78.  if Timer_Period
  79.  {
  80.   Timer[Timer_Name,"Start"] := A_TickCount
  81.   Timer[Timer_Name,"Finish"] := A_TickCount + Timer_Period
  82.   Timer[Timer_Name,"Period"] := Timer_Period
  83.   Timer_Count += 1
  84.  }
  85.  if (Timer_Opt = "R" or Timer_Opt = "Reset")
  86.  {
  87.   Timer[Timer_Name,"Start"] := A_TickCount
  88.   Timer[Timer_Name,"Finish"] := A_TickCount + Timer[Timer_Name,"Period"]
  89.  }
  90.  Timer[Timer_Name,"Now"] := A_TickCount
  91.  Timer[Timer_Name,"Left"] := Timer[Timer_Name,"Finish"] - Timer[Timer_Name,"Now"]
  92.  Timer[Timer_Name,"Done"] := true
  93.  if (Timer[Timer_Name,"Left"] > 0)
  94.   Timer[Timer_Name,"Done"] := false
  95.  if (Timer_Opt = "D" or Timer_Opt = "Done")
  96.   return Timer[Timer_Name,"Done"]
  97.  if (Timer_Opt = "S" or Timer_Opt = "Start")
  98.   return Timer[Timer_Name,"Start"]
  99.  if (Timer_Opt = "F" or Timer_Opt = "Finish")
  100.   return Timer[Timer_Name,"Finish"]
  101.  if (Timer_Opt = "L" or Timer_Opt = "Left")
  102.   return Timer[Timer_Name,"Left"]
  103.  if (Timer_Opt = "N" or Timer_Opt = "Now")
  104.   return Timer[Timer_Name,"Now"]
  105.  if (Timer_Opt = "P" or Timer_Opt = "Period")
  106.   return Timer[Timer_Name,"Period"]
  107. }
  108.  
  109. F1::
  110.  If Timer("Bash")
  111.  {
  112.   Send 1
  113.   Timer("Bash",6000)
  114.   Sleep 500
  115.  }
  116.  If Timer("Thrash")
  117.  {
  118.   Send 2
  119.   Timer("Thrash",5000)
  120.   Sleep 500
  121.  }
  122.  If Timer("Trash")
  123.  {
  124.   Send 3
  125.   Timer("Trash",8000)
  126.   Sleep 500
  127.  }
  128.  If Timer("Slash")
  129.  {
  130.   Send 4
  131.   Timer("Slash",4500)
  132.   Sleep 500
  133.  }
  134.  If Timer("Crash")
  135.  {
  136.   Send 5
  137.   Timer("Crash",17250)
  138.   Sleep 500
  139.  }
  140. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement