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.

Player Variables in Code

Player variables are only accessible when a game is running. Be prepared that the current player may change in a multiplayer game.

Inside a (game) mode you can access the current player using self.player. Alternatively, you can use self.machine.game.player but be aware that both self.machine.game and self.machine.game.player may be None.

You can use player variables like this:

player = self.machine.game.player    # do not persist the player because it may change
                                     # alternatively use self.player in modes

if not player:
   return    # do something reasonable here but do not crash in the next line

# read player variable
print(player["my_variable"])

# set a variable
player["my_variable"] = 17