self.machine.modes.credits

class mpf.modes.credits.code.credits.Credits(machine, config, name, path)

Bases: mpf.core.mode.Mode

Mode which manages the credits and prevents the game from starting without credits.

Accessing the credits mode via code

You can access the credits mode from anywhere via self.machine.modes.credits.

Methods & Attributes

The credits mode has the following methods & attributes available. Note that methods & attributes inherited from the base Mode class are not included here.

active

Return true if mode is active.

add_credit(price_tiering=True)

Add a single credit to the machine.

Parameters:price_tiering -- Boolean which controls whether this credit will be eligible for the pricing tier bonuses. Default is True.
add_mode_event_handler(event, handler, priority=0, **kwargs)

Register an event handler which is automatically removed when this mode stops.

This method is similar to the Event Manager's add_handler() method, except this method automatically unregisters the handlers when the mode ends.

Parameters:
  • event -- String name of the event you're adding a handler for. Since events are text strings, they don't have to be pre-defined.
  • handler -- The method that will be called when the event is fired.
  • priority -- An arbitrary integer value that defines what order the handlers will be called in. The default is 1, so if you have a handler that you want to be called first, add it here with a priority of 2. (Or 3 or 10 or 100000.) The numbers don't matter. They're called from highest to lowest. (i.e. priority 100 is called before priority 1.)
  • **kwargs -- Any any additional keyword/argument pairs entered here will be attached to the handler and called whenever that handler is called. Note these are in addition to kwargs that could be passed as part of the event post. If there's a conflict, the event-level ones will win.
Returns:

A GUID reference to the handler which you can use to later remove the handler via remove_handler_by_key. Though you don't need to remove the handler since the whole point of this method is they're automatically removed when the mode stops.

Note that if you do add a handler via this method and then remove it manually, that's ok too.

clear_all_credits(**kwargs)

Clear all credits.

configure_logging(logger, console_level='basic', file_level='basic')

Configure the logging for the module this class is mixed into.

Parameters:
  • logger -- The string name of the logger to use
  • console_level -- The level of logging for the console. Valid options are "none", "basic", or "full".
  • file_level -- The level of logging for the console. Valid options are "none", "basic", or "full".
debug_log(msg, *args, **kwargs)

Log a message at the debug level.

Note that whether this message shows up in the console or log file is controlled by the settings used with configure_logging().

enable_credit_play(post_event=True, **kwargs)

Enable credits play.

enable_free_play(post_event=True, **kwargs)

Enable free play.

error_log(msg, *args, **kwargs)

Log a message at the error level.

These messages will always be shown in the console and the log file.

info_log(msg, *args, **kwargs)

Log a message at the info level.

Whether this message shows up in the console or log file is controlled by the settings used with configure_logging().

start(mode_priority=None, callback=None, **kwargs)

Start this mode.

Parameters:
  • mode_priority -- Integer value of what you want this mode to run at. If you don't specify one, it will use the "Mode: priority" setting from this mode's configuration file.
  • **kwargs -- Catch-all since this mode might start from events with who-knows-what keyword arguments.

Warning: You can safely call this method, but do not override it in your mode code. If you want to write your own mode code by subclassing Mode, put whatever code you want to run when this mode starts in the mode_start method which will be called automatically.

stop(callback=None, **kwargs)

Stop this mode.

Parameters:**kwargs -- Catch-all since this mode might start from events with who-knows-what keyword arguments.

Warning: You can safely call this method, but do not override it in your mode code. If you want to write your own mode code by subclassing Mode, put whatever code you want to run when this mode stops in the mode_stop method which will be called automatically.

toggle_credit_play(**kwargs)

Toggle between free and credits play.

warning_log(msg, *args, **kwargs)

Log a message at the warning level.

These messages will always be shown in the console and the log file.