This week was implementing the attract mode, and just generally getting more familiar with Mission Pinball Framework (MPF). First up was to create a couple quick light shows. The MPF documentation suggested that I break the light shows into individual pieces, so I ended up creating a mode, drop target, kickout hole, and inlane light shows. I got the first light show working immediately. At that point I created the other light shows. So here are couple lines from the mode light show.
#show_version=6
##! show: show_attract_modes
- duration: 1
lights:
l_shoot_again: off
l_mode_sharpe: off
- duration: 1
lights:
l_shoot_again: on
l_mode_sharpe: on
...
Then I created the other light shows like the following:
!!! Warning !!! Bad code! Do not use!
- duration: 1
lights:
- l_rollover_s: off
- l_rollover_h: off
- duration: 1
lights:
- l_rollover_s: on
- l_rollover_h: on
...
When I tried to run MPF, it just crashed with no real explanation. It said “l_rollover_s” didn’t exist. I went back and checked that I had defined the light properly. Y’up, looked exactly like how I defined l_shoot_again. Maybe it was because I was trying to kick off multiple light shows. Changed it up so that I only created two light shows instead of the four I needed. Still crashed with the same issue. I emptied the light show completely, but that gave a different error. Eventually I noticed that I had a dash ‘-‘ before the light name in the shows that didn’t work, and I just had the light name in the show that did work. Uggh! It would have been nice to say something like “list not allowed” which would have pointed me to the correct issue.
MPF uses a ‘-‘ to indicate lists of instructions in some areas, and doesn’t accept them in other areas. Since I’m still getting my head around the syntax, I’m not sure when lists are available, and when they aren’t available. I think I must get better with understanding the syntax of yaml files.
Growing pains, but that is to be expected. Next up was that I want to give two different callouts when the machine is in attract mode, with 60s between the callouts. (It should also be expandable to more callouts if I need to add more) That seems pretty simple. Here was my first take at the config files to make it happen:
sound_player:
timer_after_yall_comeback_timer_complete:
howdyFolks:
# HRS: Why doesn't this work so timers can be removed? delay: 60s
bus: voice
events_when_stopped: howdy_folks_end
timer_after_howdy_folks_timer_complete:
yallComeBack:
# HRS: Why doesn't this work so timers can be removed? delay: 60s
bus: voice
events_when_stopped: yall_comeback_end
timers:
after_yall_comeback_timer:
end_value: 1
tick_interval: 60s
start_running: false
control_events:
- event: mode_attract_started
action: restart
- event: yall_comeback_end
action: restart
after_howdy_folks_timer:
end_value: 1
tick_interval: 60s
start_running: false
control_events:
- event: howdy_folks_end
action: restart
I tried to use the “delay: 60s” at either the beginning or the end of the clip, and it just didn’t make a difference. MPF said it was a valid command but it ignored it. (Maybe it isn’t implemented in 0.80?). That would have meant that I wouldn’t need timers. I gave up on that idea and moved on.
Since the delay command didn’t work, I needed a couple of timers (one for each sound). That kinda sucks, but it does work. The after_yall_comeback_timer is kicked off when attract mode is started. When the after_yall_comeback_timer expires, it plays howdyFolks. After howdyFolks clip ends, it starts the after_howdy_folks_timer. When the after_howdy_folks_timer expires, it plays yallComeBack. It then repeats the process.
This works…but it kinda sucks. If I wanted to have 10 different clips that I wanted to rotate through, I would need to create 10 timers for this to happen. Maybe I could do something clever with AudioStreamRandomizer in Godot, but I’m trying to learn MPF at this moment, not Godot and I really want MPF to iterate over my sounds. There is a play_list option with maybe using crossfade_time to get the 60s between samples, but that is only available using the old MPF-MC, not Godot.
Next I decided I wanted to implement it using a machine variable. Here is the code that make that work:
sound_player:
timer_attract_catcall_timer_complete{machine.last_catcall_callout == 1}:
howdyFolks:
bus: music
events_when_stopped: attract_catcall_end
timer_attract_catcall_timer_complete{machine.last_catcall_callout == 0}:
yallComeBack:
bus: music
events_when_stopped: attract_catcall_end
timers:
attract_catcall_timer:
end_value: 1
tick_interval: 60s
start_running: false
control_events:
- event: mode_attract_started
action: restart
- event: attract_catcall_end
action: restart
variable_player:
attract_catcall_end:
last_catcall_callout:a
action: add_machine
int: 1
attract_catcall_end{machine.last_catcall_callout >= 2}:
last_catcall_callout:
action: set_machine
int: 0
This is a round-about way, but it is a little bit cleaner. The attract_catcall_timer is started when attract is entered. When the timeout occurs, it plays the appropriate sound depending on the last_catcall_callout machine variable. After the clip finishes, it updates the last_catcall_callout machine variable by incrementing it in the variable_player, then using a second update in the variable_player to set it to 0 if past the number of clips. This is still dirty and I don’t feel I should need multiple variable_player entries. If I had 20 clips I wanted to play, I would need 20 conditional statements based on the timer_attract_catcall_timer_complete event occurring. I now only need one timer that I can use which is cleaner.
After watching Jan’s video on machine and player variables, he pointed out that setting the value can be a full on python statement. With one more slight changed to the variable player, it is much cleaner. Here is the final version with increments it and resets it to 0 in a single statement. It is definitely less readable on first glance, but I’ll get used to it.
variable_player:
attract_catcall_end:
last_catcall_callout:
action: set_machine
int: 0 if machine.last_catcall_callout + 1 >= 2 else machine.last_catcall_callout + 1
It seems to be pointing to the fact, that if I want to do clever stuff, such as using the flippers to rotate inlanes in both directions, it is probably just going to be easier to do it in code. That will be the next thing to look into.