Switches and Tags

37 views
Skip to first unread message

kaydeeH

unread,
Oct 31, 2024, 10:19:05 AMOct 31
to MPF Users
Hi all,

Quick question... Aside from writing custom code, is there a quick and easy way to say, "if any switch EXCEPT 'switchX' is hit, then do something"? Kind of like a hurryup that's cancelled if the target switch isn't the very next switch you hit.

I feel like, if there is an answer, it's going to involve tags and/or shots, but I'm not sure how to go from tagging the switches to essentially evaluating if any switch except for a given switch is hit at a specific point in the game (without custom code). 

If there's nothing, then there's nothing, but I didn't want to run off and write custom code if there's a built-in option.

Thanks in advance,
Kadyee

kaydeeH

unread,
Oct 31, 2024, 11:51:07 AMOct 31
to MPF Users
In an effort to keep things moving, I started working on a custom script for this (I figured I could at least learn something while I wait), but I'm stuck dealing with futures. I get what they are in concept, but I've never worked with them before and I'm just not sure where to go with this. Here's what I have so far...

Screenshot 2024-10-31 084152.png

The list of switches are the switches that will kill the extra ball if they get hit. The switch_controller.wait_for_any_switch() should (eventually) give me the switch from that list that first goes active for at least 1ms, but it's in the form of a Future, which I guess makes sense given that it's a wait and see thing. However, I can't find an example of dealing with futures on the intertubes that helps me to understand what to do next in this particular scenario (or I'm too dense to grasp what they're trying to show me). How do I go from awaiting the future's response to capturing the switch that's returned from the future when it detects the switch? Once I have the detected switch (any switch from the list, really), then it's a simple matter of posting an event. This has to be simple, but Python is not my strong suit, and I'm just not grasping these futures.

As written, I never get the list of kill switches printed out. The event "outlane_eb_ready" definitely fires (confirmed in the log and the monitor window). If I move the switch lookup and the for loop up into the on_load() they print out just fine, so I'm either never getting to _await_kill_switches(), or something about it being an async def is doing something I don't understand.

Thanks again,
Kaydee

kaydeeH

unread,
Oct 31, 2024, 4:59:13 PMOct 31
to MPF Users
Just noticed I get some console output with the above implementation of custom code:

    RuntimeWarning: coroutine 'DrainToExtraBall._await_kill_switches' was never awaited

Definitely doing something wrong... still definitely do not know what. :P

Anthony van Winkle

unread,
Oct 31, 2024, 7:25:00 PMOct 31
to MPF Users

This is definitely not a simple road to go down, and you may be better of sticking with the traditional approach. For uses like this I typically create a special "frenzy" mode that has one shot with all the switches assigned. Yes you have to manually set the switches, but the overhead of all the listeners is limited to just this mode being active. You can use the frenzy shot_hit event to trigger your behavior, and a separate shot for your failure switch.

kaydeeH

unread,
Oct 31, 2024, 7:42:16 PMOct 31
to MPF Users
That makes a lot of sense, thank you! I had considered a separate mode, but I hadn't thought about one massive super shot for all the kill switches... nice! This mode will only be active for about 5 seconds either way, so I'm not too worried about the overhead. Much appreciated!
Reply all
Reply to author
Forward
0 new messages