Adding custom code to your game
While one of the goals of MPF is to allow you to do as much of your game’s configuration as possible with the config files, we recognize that many people will want to mix in some custom code to their machines.
Fortunately that’s easy to do, and you don’t have to “hack” MPF or break anything to make it happen!
The amount of custom code you use is up to you, depending on your personal preferences, your comfort with Python, and what exactly you want to do with your machine.
Some people will use the config files for 99% of their machine, and only add a little custom code here and there. Others will only want to use the configs for the “basic” stuff and then write all their game logic in Python. Either option is fine with us!
When you decide that you want to add some custom Python code into your game, there are two ways you can do this:
- Mode-specific code, which allows you to write custom Python code which is only active when a particular game mode is active.
- Machine-wide code, useful for dealing with custom hardware, like the crane in Demolition Man.
Something missing or wrong? You can fix it!
This website is edited by people like you! Is something wrong or missing? Is something out of date, or can you explain it better?
Please help us! You can fix it yourself and be an official "open source" contributor!
It's easy! See our Beginner's guide to editing the docs.
Page navigation via the keyboard: < >
You can navigate this site via the keyboard. There are two modes:
General navigation, when search is not focused:
- F , S , / : open search dialog
- P , , : go to previous page
- N , . : go to next page
While using the search function:
- Down , Up : select next / previous result
- Esc , Tab : close search
- Enter : go to highlighted page in the results