Warning

This documentation is for an unreleased version of MPF!

This is the developer documentation for MPF 0.51, which is the “dev” (next) release of MPF that is a work-in-progress. Use the “Read the Docs” link in the lower left corner to view the developer docs for the version of MPF you’re using.

self.machine.counters.*

class mpf.devices.logic_blocks.Counter(machine: mpf.core.machine.MachineController, name: str)

Bases: mpf.devices.logic_blocks.LogicBlock

A type of LogicBlock that tracks multiple hits of a single event.

This counter can be configured to track hits towards a specific end-goal (like number of tilt hits to tilt), or it can be an open-ended count (like total number of ramp shots).

It can also be configured to count up or to count down, and can have a configurable counting interval.

Accessing counters in code

The device collection which contains the counters in your machine is available via self.machine.counters. For example, to access one called “foo”, you would use self.machine.counters.foo. You can also access counters in dictionary form, e.g. self.machine.counters['foo'].

You can also get devices by tag or hardware number. See the DeviceCollection documentation for details.

Methods & Attributes

Counters have the following methods & attributes available. Note that methods & attributes inherited from base classes are not included here.

complete()

Mark this logic block as complete.

Posts the ‘events_when_complete’ events and optionally restarts this logic block or disables it, depending on this block’s configuration settings.

completed

Return if completed.

count(**kwargs)

Increase the hit progress towards completion.

This method is also automatically called when one of the count_events is posted.

disable(**kwargs)

Disable this logic block.

Automatically called when one of the disable_event events is posted. Can also manually be called.

enable(**kwargs)

Enable this logic block.

Automatically called when one of the enable_event events is posted. Can also manually be called.

enabled

Return if enabled.

get_start_value() → int

Return start count.

raise_config_error(msg, error_no, *, context=None)

Raise a ConfigFileError exception.

reset(**kwargs)

Reset the progress towards completion of this logic block.

Automatically called when one of the reset_event events is called. Can also be manually called.

restart(**kwargs)

Restart this logic block by calling reset() and enable().

Automatically called when one of the restart_event events is called. Can also be manually called.

stop_ignoring_hits(**kwargs)

Cause the Counter to stop ignoring subsequent hits that occur within the ‘multiple_hit_window’.

Automatically called when the window time expires. Can safely be manually called.

value

Return value or None if that is currently not possible.