Cycle timer

From Seltanikor
Jump to navigationJump to search


This is a timer written by Evangeline for Mitsu, which produces a rotating cycle of events, with a ten-second interval between events.

Events can be in the same room or in different rooms - these values are returned for a given timer stage by calling the event_list and cycle_location properties.

Code cycle_init:

  sched(10, cycle_setup, repeat=True) # Calls the cycle_timer to make an event every ten seconds. If you go any shorter than this, it will fail silently.

Code cycle_setup:

  eventloc(locations.backstage, cycle_timer("The timer is running.")) # This is useful to know that your timer is still going, since its events may vary in location.
  # Having this also means that the initial sched() call only has to run one line of code itself, which was a necessary workaround for me.

Code (args) cycle_timer:

args: message

  realm.cycle_stage = realm.cycle_stage + 1
  if realm.cycle_stage > 5: # 'How many cycle stages, maximum.' Make sure to call the Realm property or you'll end up with location variables mucking everything up.
     realm.cycle_stage = 0 # Start over when you reach the end.
  sched(5, cycle_event(cycle_location(realm.cycle_stage), (random.choice(event_list(realm.cycle_stage))))) # Calls a random event from the event list for the given room.
  return message

Code (args) cycle_event:

args: loc, message

  eventloc(loc, message) #This is just a wrapper class. Feel free to leave it out if you're very confident that you'll only ever want to call eventloc when your timer triggers.

Code (args) cycle_location

args: stage

  if stage == 0:
     return locations.es_hall
  elif stage == 1:
     return locations.lounge
  ... etc, for all cycle stages.

Code (args) event_list

args: stage

  if stage == 0:
     return eh_list
  elif stage == 1:
     return lng_list
  ... etc, for all cycle stages. 

Each event list is a Value field filled with strings, eg: ['A cold breeze passes by you.', 'Was that a footstep?'], etc.