This is the dev documentation for an unreleased version of MPF!

This is the documentation for MPF 0.56, which is the “dev” (next) release of MPF that is a work-in-progress. Unless you’re specifically looking for this version, you probably want to use the version of documentation called “latest” which is for the latest released version of MPF. That documentation is at docs.missionpinball.org/en/latest.

Handler Priorities

When you have some code you want to register to be a handler for an event, you can optionally specify a priority. (Priority is just an integer value.) The default priority for events is 1. If you want a guarantee that a certain event handler will fire last, then register that handler with a priority that’s lower than any other handler for that event. And if you want to guarantee that a handler fires first, register it with a higher priority. (In this case, “higher” and “lower” are literal. A handler with a priority of 500 will be called before a handler of 100.)

The actual integer values of the priorities are arbitrary. They’re called one-by-one, one after the other, in order from highest to lowest. Whether your priorities are 3, 2, and 1, or 1000, 100 and 0, or 1000, 999, 998, and 1 makes no difference.

MPF automatically registers event handlers from modes with the priority of that mode, meaning high-priority modes get access to an event before lower-priority modes. (This is useful since it gives higher-priority modes a chance to “block” events from lower-priority modes.)

See Device Control Events on how to use event handlers in devices.