self.machine

class mpf.core.machine.MachineController(mpf_path: str, machine_path: str, options: dict)

Bases: mpf.core.logging.LogMixin

Base class for the Machine Controller object.

The machine controller is the main entity of the entire framework. It's the main part that's in charge and makes things happen.

Parameters:options -- Dictionary of options the machine controller uses to configure itself.
options

dict -- A dictionary of options built from the command line options used to launch mpf.py.

config

dict -- A dictionary of machine's configuration settings, merged from various sources.

game

mpf.modes.game.code.game.Game -- the current game

machine_path

The root path of this machine_files folder

plugins
scriptlets
hardware_platforms
events

mpf.core.events.EventManager

Accessing the machine controller in code

The machine controller is the main component in MPF, accessible via self.machine. See the Overview & Tour of MPF code for details.

Methods & Attributes

The machine controller has the following methods & attributes available. Note that methods & attributes inherited from base classes are not included here.

add_platform(name)

Make an additional hardware platform interface available to MPF.

Parameters:name -- String name of the platform to add. Must match the name of a platform file in the mpf/platforms folder (without the .py extension).
clear_boot_hold(hold)

Clear a boot hold.

create_data_manager(config_name)

Return a new DataManager for a certain config.

Parameters:config_name -- Name of the config
create_machine_var(name, value=0, persist=False, expire_secs=None, silent=False)

Create a new machine variable.

Parameters:
  • name -- String name of the variable.
  • value -- The value of the variable. This can be any Type.
  • persist -- Boolean as to whether this variable should be saved to disk so it's available the next time MPF boots.
  • expire_secs -- Optional number of seconds you'd like this variable to persist on disk for. When MPF boots, if the expiration time of the variable is in the past, it will be loaded with a value of 0. For example, this lets you write the number of credits on the machine to disk to persist even during power off, but you could set it so that those only stay persisted for an hour.
get_machine_var(name)

Return the value of a machine variable.

Parameters:name -- String name of the variable you want to get that value for.
Returns:The value of the variable if it exists, or None if the variable does not exist.
get_platform_sections(platform_section, overwrite)

Return platform section.

init_done()

Finish init.

Called when init is done and all boot holds are cleared.

is_machine_var(name)

Return true if machine variable exists.

power_off(**kwargs)

Attempt to perform a power down of the pinball machine and ends MPF.

This method is not yet implemented.

register_boot_hold(hold)

Register a boot hold.

register_monitor(monitor_class, monitor)

Register a monitor.

Parameters:
  • monitor_class -- String name of the monitor class for this monitor that's being registered.
  • monitor -- String name of the monitor.

MPF uses monitors to allow components to monitor certain internal elements of MPF.

For example, a player variable monitor could be setup to be notified of any changes to a player variable, or a switch monitor could be used to allow a plugin to be notified of any changes to any switches.

The MachineController's list of registered monitors doesn't actually do anything. Rather it's a dictionary of sets which the monitors themselves can reference when they need to do something. We just needed a central registry of monitors.

remove_machine_var(name)

Remove a machine variable by name.

If this variable persists to disk, it will remove it from there too.

Parameters:name -- String name of the variable you want to remove.

Remove a machine variable by matching parts of its name.

Parameters:
  • startswith -- Optional start of the variable name to match.
  • endswith -- Optional end of the variable name to match.

For example, if you pass startswit='player' and endswith='score', this method will match and remove player1_score, player2_score, etc.

reset()

Reset the machine.

This method is safe to call. It essentially sets up everything from scratch without reloading the config files and assets from disk. This method is called after a game ends and before attract mode begins.

run()

Start the main machine run loop.

set_default_platform(name)

Set the default platform.

It is used if a device class-specific or device-specific platform is not specified.

Parameters:name -- String name of the platform to set to default.
set_machine_var(name, value, force_events=False)

Set the value of a machine variable.

Parameters:
  • name -- String name of the variable you're setting the value for.
  • value -- The value you're setting. This can be any Type.
  • force_events -- Boolean which will force the event posting, the machine monitor callback, and writing the variable to disk (if it's set to persist). By default these things only happen if the new value is different from the old value.
stop(**kwargs)

Perform a graceful exit of MPF.

validate_machine_config_section(section)

Validate a config section.

verify_system_info()

Dump information about the Python installation to the log.

Information includes Python version, Python executable, platform, and core architecture.