Persisting the State of a Logic Block in a Player Variable
Related Config File Sections:
Prior to MPF 0.50 the state of logic blocks has been persisted to player
variables. This only longer holds true for player specific blocks (e.g.
if you set
True). In that case the variable will be
(logic_block)_state. For example, a logic block called
"logic_block_1" would store its state in a player variable called
logic_block_1_state. When you do not want to persist the value you can
reference it using
device.counters.logic_block_1.value (also if you
You can easily use this numerical value in a text widget to show the number of combos complete, or the number of pop bumper hits required for super jets, etc. This player variable "state" is different than the state of the logic block itself, which is an object with enabled, completed, and value attributes. Note the difference in accessing the logic block state as a dynamic value vs. placeholder text:
##! mode: my_mode counters: logic_block_1: count_events: count_up_event variable_player: counter_logic_block_1_hit: # this is triggered when the counter changes my_widget_placeholder: 100 * device.counters.logic_block_1.value # The logic block stores the count as the 'value' attribute widgets: counter_widget: - type: text text: (my_widget_placeholder) Hits! # This placeholder is set by variable_player when the counter changes #! widget_player: #! show_widget_event: counter_widget ##! test #! start_game #! start_mode my_mode #! post show_widget_event #! post count_up_event #! advance_time_and_run .1 #! assert_text_on_top_slide "100 Hits!"
In this example we persist the value of the counter in the player
counter_hit to use it in a slide.
The player variable is only saved if the logic block is configured with
persist_state: True. If
False, the logic block
value will _not be saved under any variable name (not even the
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