Repeat
From EventScripts Community Encyclopedia
[edit] Methods#Create myRepeat = repeat.create('repeatName', function, (args), {kw}) # Start myRepeat.start(interval, limit) # Stop myRepeat.stop() # Pause myRepeat.pause() # Resume myRepeat.resume() # Delete myRepeat.delete() # Status myRepeat.status() ''' 0 = Non-Existant 1 = Stopped 2 = Running 3 = Started, but paused ''' # Find myRepeat = repeat.find('repeatName') ''' If no instance found, returns None ''' # Info myRepeat.info('Attribute Name') ''' Another method we can use to retrieve the attributes listed above ''' [edit] Attributes# All attributes below are only available in EventScripts 2.0.248c+ # The time it will take to complete the repeat (float) myRepeat['time'] # The time remaining in the repeat (float) myRepeat['timeleft'] # The number loops that the repeat has fired (int) myRepeat['count'] # The number of loops remaining in the repeat (int) myRepeat['remaining'] # The delay between each time the repeat is fired (float) myRepeat['interval'] # The number of times the repeat will run (int) myRepeat['limit'] # The function that is called when the repeat fires myRepeat['command'] # The arguments passed to the function that the repeat fires myRepeat['args'] # The keyword passed to the function when the repeat fires myRepeat['kw'] [edit] Exampleimport es import repeat def load(): # Set myVar to "blah", so we can pass this is an argument to "myRepeat" myVar = 'blah' # Create the repeats we will use myRepeat = repeat.create('myRepeat', testCmd, (myVar)) pauseRepeat = repeat.create('pauseRepeat', pauseCmd, ()) # Start the repeat "myRepeat" myRepeat.start(1, 10) def unload(): # Delete both repeats we created repeat.delete('myRepeat') repeat.delete('pauseRepeat') def testCmd(var): # Retrieve the instance of the previously created "myRepeat" myRepeat = repeat.find('myRepeat') # If the instance is not found (None), do nothing if not myRepeat: return # See if the remaining number of loops is 5 if myRepeat['remaining'] == 5: # Echo myRepeat Information es.dbgmsg(0, '----------------------------') es.dbgmsg(0, 'Loop Count: %s' %myRepeat['count']) es.dbgmsg(0, 'Start Time: %s' %myRepeat['time']) es.dbgmsg(0, 'Loop Interval: Every %s seconds' %myRepeat['interval']) es.dbgmsg(0, 'Time Remaining: %s' %myRepeat['timeleft']) es.dbgmsg(0, 'Loops Remaining: %s' %myRepeat['remaining']) es.dbgmsg(0, '----------------------------') # Pause myRepeat myRepeat.pause() es.dbgmsg(0, 'Pausing myRepeat!!!') # Retrieve the instance of the previously created "pauseRepeat" pauseRepeat = repeat.find('pauseRepeat') # If the instance is not found (None), do nothing if not pauseRepeat: return # Start pauseRepeat pauseRepeat.start(1, 5) else: # Echo myRepeat Information es.dbgmsg(0, '----------------------------') es.dbgmsg(0, 'Loop Count: %s' %myRepeat['count']) es.dbgmsg(0, 'Start Time: %s' %myRepeat['time']) es.dbgmsg(0, 'Loop Interval: Every %s seconds' %myRepeat['interval']) es.dbgmsg(0, 'Time Remaining: %s' %myRepeat['timeleft']) es.dbgmsg(0, 'Loops Remaining: %s' %myRepeat['remaining']) es.dbgmsg(0, '----------------------------') def pauseCmd(): # Retrieve the instance of the previously created "pauseRepeat" pauseRepeat = repeat.find('pauseRepeat') # If the instance is not found (None), do nothing if not pauseRepeat: return # See if the remaining number of loops is 0 if pauseRepeat['remaining'] == 0: # Retrieve the instance of the previously created "myRepeat" myRepeat = repeat.find('myRepeat') # If the instance is not found (None), do nothing if not myRepeat: return # Echo that we are restarting "myRepeat" es.dbgmsg(0, 'Resuming myRepeat!!!') # Resume the previously pause "myRepeat" myRepeat.resume() else: # Echo how much time before we resume "myRepeat" es.dbgmsg(0, 'Resuming myRepeat in: %s' %pauseRepeat['remaining']) [edit] Example Output''' ---------------------------- The Count = 1 Start Time: 10.0 Loop Interval: Every 1.0 seconds Time Remaining: 9.0 Loops Remaining: 9 ---------------------------- ---------------------------- The Count = 2 Start Time: 10.0 Loop Interval: Every 1.0 seconds Time Remaining: 8.0 Loops Remaining: 8 ---------------------------- ---------------------------- The Count = 3 Start Time: 10.0 Loop Interval: Every 1.0 seconds Time Remaining: 7.0 Loops Remaining: 7 ---------------------------- ---------------------------- The Count = 4 Start Time: 10.0 Loop Interval: Every 1.0 seconds Time Remaining: 6.0 Loops Remaining: 6 ---------------------------- ---------------------------- The Count = 5 Start Time: 10.0 Loop Interval: Every 1.0 seconds Time Remaining: 5.0 Loops Remaining: 5 ---------------------------- Pausing myRepeat!!! myRepeat resuming in: 4 myRepeat resuming in: 3 myRepeat resuming in: 2 myRepeat resuming in: 1 Resuming myRepeat!!! ---------------------------- The Count = 6 Start Time: 10.0 Loop Interval: Every 1.0 seconds Time Remaining: 4.0 Loops Remaining: 4 ---------------------------- ---------------------------- The Count = 7 Start Time: 10.0 Loop Interval: Every 1.0 seconds Time Remaining: 3.0 Loops Remaining: 3 ---------------------------- ---------------------------- The Count = 8 Start Time: 10.0 Loop Interval: Every 1.0 seconds Time Remaining: 2.0 Loops Remaining: 2 ---------------------------- ---------------------------- The Count = 9 Start Time: 10.0 Loop Interval: Every 1.0 seconds Time Remaining: 1.0 Loops Remaining: 1 ---------------------------- ---------------------------- The Count = 10 Start Time: 10.0 Loop Interval: Every 1.0 seconds Time Remaining: 0.0 Loops Remaining: 0 ---------------------------- ''' [edit] Note
[edit] See Also |
|
