def on_load(self): """Called automatically when this Scriptlet is loaded.""" # add code here to do whatever you want your Scriptlet to do when the # machine boots up. # This example Scriptlet has lots of different examples which show (some) # of the things you can do. Feel free to delete everything from here on # down when you create your own Scriptlet. # you can access the machine object via self.machine, like this: print self.machine print self.machine.physical_hw # etc. # you can access this Scriptlet's name (based on the class name above): print self.name # will print `YourScriptletName` in this case # you can write to the log via self.log: # The logger will be prefaced with Scriptlet.YourScriptletName self.log.info("This is my Scriptlet") self.log.debug("This is a debug-level log entry") # you can access machine configuration options via self.machine.config: print self.machine.config['Game']['Balls per game'] # feel free to add your own entries to the machine configuration files, # like: self.machine.config['YourScriptlet']['Your Setting'] # you can post events which other modules can pick up: self.machine.events.post('whatever_event_you_want') # you can register handlers to act on system events self.machine.events.add_handler('ball_add_live', self.my_handler) # you can create periodic timers that are called every so often from mpf.system.timing import Timer self.machine.timing.add(Timer(callback=self.my_timer, frequency=10)) # (Or save a reference to the timer if you want to remove() it later.) # you can register a handler for the machine tick which will be called # every machine tick! self.machine.events.add_handler('timer_tick', self.tick)
def _initialize(self): """Internal method which initializes this display. This is separate from # __init__ because we have to wait until Pygame has been initialized. """ # Create a default surface for this display self.surface = pygame.Surface((self.width, self.height), depth=self.depth) if self.depth == 8: self.surface.set_palette(self.palette) self.machine.display.displays[self.name] = self if not self.machine.display.default_display: self.machine.display.default_display = self self.current_slide = self.add_slide('default') self.machine.timing.add( Timer(self.update, frequency=1 / float(self.config['fps'])))
def _initialize_phase_2(self): self.machine.timing.add( Timer(callback=self.flash_diag_led, frequency=0.5)) self.machine.events.add_handler('timer_tick', self._tick)
def _create_system_timer(self): # Creates the system timer which drives this mode timer's tick method. self._remove_system_timer() self.timer = Timer(callback=self._timer_tick, frequency=self.tick_secs) self.machine.timing.add(self.timer)