Implementing Light Group Based on Number of Target Hits

48 views
Skip to first unread message

atum

unread,
Mar 18, 2020, 5:10:31 PM3/18/20
to MPF Users
I am looking to implement something where I have four targets, and four lights.  I don't care which target you hit, but when you hit one, I want the first light to come on.  Two total hits would light the first two, etc.  So once you get all four lit, you can make another shot to "collect", which will unlight the four lights, and you start back over.  This is similar to BM66's Gadget targets where it will spot targets if you have already made the one that you hit.  So if someone knows how that works, I can use that same thing.

I am trying to implement this in VPX as of now, and I am not sure if that is causing the issue.  When I add this code in, it crashes VPX when I start a game, and it just picks a random coil, and says forcibly closed and throws an error.

Here is what I have for my mode:
#config_version=5
##! mode: item
mode
:
    start_events
: ball_starting
       
   
shots
:
    item_targets
:
       
switch: s_I, s_T, s_E, s_M
    item_collect
:
       
switch: s_lock_3
                   
counters
:
      item_count
:
        count_events
: item_targets_hits
        starting_count
: 0
        count_complete_value
: 4
        count_interval
: 1
        direction
: up
        persist_state
: true
        debug
: true
       
show_player
:
    device
.counters.item_count > 0:
        item_lights
:
            loops
: -1
            show_tokens
:
                led
: light_i
    device
.counters.item_count > 1:
        item_lights
:
            loops
: -1
            show_tokens
:
                led
: light_t
    device
.counters.item_count > 2:
        item_lights
:
            loops
: -1
            show_tokens
:
                led
: light_e
    device
.counters.item_count > 3:
        item_lights
:
            loops
: -1
            show_tokens
:
                led
: light_m

Here is my show that I am referencing for item lights, and passing through the token led to determine which to light:
#show_version=5
##! show: item_lights

- time: 0
  lights
:
   
(led): white

Thanks in advance if you have any input that might help me!

mike wiz

unread,
Mar 18, 2020, 5:26:01 PM3/18/20
to MPF Users

I would probably use a shot_group for this. 

Also I don't think you are using device.counters.item_count correctly, that is why it is crashing.  To use a conditional value the statement would be device.counters.item_count.value


Erno Lahdenperä

unread,
Mar 18, 2020, 6:13:26 PM3/18/20
to mpf-...@googlegroups.com
You could make a shot with profile that has four steps and manual advance, advance event when shotgroup stadups hit and restart event when collect hit. 

--
You received this message because you are subscribed to the Google Groups "MPF Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mpf-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mpf-users/5979fa55-b1f3-4b7f-b511-902eb50735fb%40googlegroups.com.

atum

unread,
Mar 18, 2020, 6:27:59 PM3/18/20
to MPF Users
Mike,

Thanks for that.  I have messed with this so many times, that I missed the .value at the end of all my statements.  However, this still did not fix it.

I also had them as a shot_group with a shot_profile at one point, but thought maybe I screwed something up with that, so I tried to go "back to basics" here.

I have never used a counter before, but in looking at the logs, it doesn't seem like it is getting updated as I would expect.

2020-03-18 17:13:19,953 : INFO : EventManager : Event: ======'logicblock_item_count_updated'====== Args={'value': 0, 'enabled': True}

I would have expected to see the value go up to 1, then 2, etc. as multiple hits were achieved.  But all of them have a value of 0.

Avery

atum

unread,
Mar 18, 2020, 6:57:09 PM3/18/20
to MPF Users
iizi,

Thanks for the tip, as it looks a bit cleaner.  If I punch in the lights up above, I can get them to work.  It only lights the one in front of that target, instead of the next in the list, but it works.  So I believe I have that part working as expected.

Now onto what you suggested.  I implemented this, and it doesn't crash the game, but doesn't light up the targets:
shot_groups:
    item_targets
:
        shots
: target_i, target_t, target_e, target_m
        reset_events
: item_targets_default_lit_complete
        enable_events
: ball_starting
        disable_events
: ball_ending
       
shot_profiles
:
    item_profile
:
        states
:
           
- name: letter_i
              show_tokens
:
                light
: light_i
           
- name: letter_t
              show_tokens
:
                light
: light_i, light_t
           
- name: letter_e
              show_tokens
:
                light
: light_i, light_t, light_e
           
- name: letter_m
              show_tokens
:
                light
: light_i, light_t, light_e, light_m

This doesn't capture the manual stepping through you described, because I couldn't really figure that out from the documentation.  I am also not even sure if I can cram multiple tokes at once through here.  But even the first hit doesn't light the first letter (i), so I think it is something beyond that.

Thanks everyone!

Anthony van Winkle

unread,
Mar 18, 2020, 7:03:11 PM3/18/20
to mpf-...@googlegroups.com
Hey atum, here's a rough breakdown of how you might accomplish that.

We'll start with the main piece: a shot that awards something when it's hit after all four targets are lit. That shot can have a shot_profile with 5 steps (from 0 lights lit to 4 lights lit), corresponding to how many of the lights are lit. We use the name of the shot_profile state to know the number.
shots:
  target_jackpot_shot
:
    shot_profile
: target_jackpot_profile

shot_profiles
:
  target_jackpot_profile
:
    states
:
     
- name: zero
        show
: targets_zero_lit
     
- name: one
        show
: targets_one_lit
     
...etc


Then to hit our award shot, we'll listen for _any_ of the four targets. We do that by putting the targets in a shot_group and listening for any hit event on that group. Each hit will advance the award shot to the next step of its profile, which changes the show to the corresponding number of lights being lit.
shot_groups:
  jackpot_counter_targets
:
    shots
: target1, target2, target3, target4

shots
:  
  target_jackpot_shot
:
    shot_profile: target_jackpot_profile
    hit_events
: jackpot_counter_targets_hit
  target1:
    switch: s_target1
  target2:
    switch: s_target2
  ...etc



When a shot is hit, it posts many events. One of them includes the state name of the profile, so if the final shot profile state name is "four" we can trigger our success condition on that, which will reset the shot to it's initial (zero-lit) state. You can also use the award event to do any other things you need.
event_player:
  target_jackpot_shot_four_hit:
    - award_jackpot


shots:
  target_jackpot_shot:
   
shot_profile: target_jackpot_profile
    hit_events: jackpot_counter_targets_hit
    reset_events: award_jackpot
  

That's not complete code, but hopefully it gets you in the right direction!

--
You received this message because you are subscribed to the Google Groups "MPF Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mpf-users+...@googlegroups.com.
Message has been deleted

atum

unread,
Mar 18, 2020, 9:30:01 PM3/18/20
to MPF Users
Anthony,

Thanks for the detail and examples that you provided.  I was able to implement this and fought with it for a bit, but now I will come back to ask if anyone can figure out why my shots cannot be hit multiple times.  I have the four targets, and they will count up, but only to state 3.  I cannot get to state 4, and I am not sure why that is.  Additionally, each target can only be hit one time.  So if I hit target T, it cannot be hit again to light anything else.  I have to go through each one, but as I said, I can only get to three.  Hitting all four does not advance to state four.

I tried adding reset/restart_events to the shots and shot groups, but neither seems to be the right solution.  Also, for my event player, I don't have a real thing to happen at this point, but am hoping that is not the root of my issues.

shots:
    target_i
:
       
switch: s_I
    target_t
:
       
switch: s_T
    target_e
:
       
switch: s_E
    target_m
:
       
switch: s_M
    item_collect
:
        profile
: item_collect_profile
        hit_events
: item_counter_targets_hit
        reset_events
: award_item
                   
shot_groups
:
    item_counter_targets
:
        shots
: target_i, target_t, target_e, target_m
        reset_events
: item_counter_targets_hit
       
shot_profiles
:
    item_collect_profile
:
        states
:
         
- name: zero
         
- name: one
            show
: targets_lit_one
         
- name: two
            show
: targets_lit_two
         
- name: three
            show
: targets_lit_three
         
- name: four
            show
: targets_lit_four
             
event_player
:
    item_collect_four_hit
:
       
- award_item

Avery

Anthony van Winkle

unread,
Mar 18, 2020, 10:12:05 PM3/18/20
to MPF Users
Hey Avery, everything there looks good, not sure why it's not working. I've never tried a profile state without a show, I don't know why that wouldn't work but you could try show: off on your first state just to see.

Otherwise, it's time to turn to the logs! All these things will post their events in the logs, so you can look there and see what's happening.
  • When you hit a target switch, is the shot registering as hit? 
  • When the target shot shows a hit, does the shot group register a hit?
  • When the shot group shows a hit, does the collect shot change state?
  • What state is the collect shot starting at? What state is it ending at?
These can at least help you figure out *where* the problem is happening, which is the first step to solving it.

atum

unread,
Mar 18, 2020, 10:36:08 PM3/18/20
to MPF Users
Anthony,

Slight improvement, as now it lets it go all the way to four, but does not reset.
    • When you hit a target switch, is the shot registering as hit?
      • Yes, but only one time per target, and the same target was hit multiple times, but does not register.
    • When the target shot shows a hit, does the shot group register a hit?
      • No, , but the item_counter does go up, which I has a hit even for the group (so maybe this counts)
    • When the shot group shows a hit, does the collect shot change state?
      • Yes, it increments by one.
    • What state is the collect shot starting at? What state is it ending at?
      • I could have sworn I saw this earlier, and searched for zero.  However, now I cannot seem to find this value in the logs.

    2020-03-18 21:19:49,160 : EventManager : Event: ======'player_shot_target_i'====== Args={'value': 1, 'prev_value': 0, 'change': 1, 'player_num': 1}
    2020-03-18 21:19:49,164 : EventManager : Event: ======'player_shot_item_collect'====== Args={'value': 2, 'prev_value': 1, 'change': 1, 'player_num': 1}
    2020-03-18 21:19:49,166 : EventManager : Event: ======'player_shot_target_i'====== Args={'value': 0, 'prev_value': 1, 'change': -1, 'player_num': 1}

    shot_target_i will not appear again this entire game, regardless of number of times that it was hit.

    Thanks again,

    Avery

    atum

    unread,
    Mar 19, 2020, 7:18:51 PM3/19/20
    to MPF Users
    All following/helping,

    I super simplified this to just have this snipped of code.  No profile, not groups, no nothing.  However, this will only let the shot trigger one time during the mode, but it should be able to be hit multiple times during the course of this mode.  Is there a reset/restart that I need to add to allow this?  Any thoughts would be appreciated!

    shots:
        target_m:
            switch: s_M
            debug: true

    atum

    unread,
    Mar 20, 2020, 12:09:15 AM3/20/20
    to MPF Users
    In digging through this is an issue with my VPX code.  It is keeping the switches locked on once I hit the target.  Thus it cannot be hit again, because the switch is still tripped.  I am working out figuring out how to get this unlocked.  Not sure how, yet, but need to get it to set back to false after the hit event is over.

    atum

    unread,
    Apr 18, 2020, 2:34:05 PM4/18/20
    to MPF Users
    Resolving this ticket.  Just full circle if anyone stumbles upon this in the future.  When using the two applications together, standup targets and some rollovers do not reset as they are supposed to.  They trigger to active, but do not go back to inactive.  So they need a little different code.

    This notation works where the ball will rest on the switch for multiple cycles and thus trip both on and off:
    Sub Lock1_hit:Controller.Switch(20) = True:End Sub
    Sub Lock1_unhit:Controller.Switch(20) = False:End Sub

    If it is a quick hit like bouncing off a target or full speed over a rollover, you will need to play with the debounce in MPF or adjust the code to automatically trip on and off in VPX (which is what I did, as I am not sure I will run into those issues with a physical machine and don't want to have to dig it out later):
    Sub LOrbit_hit
       
    If Controller.Switch(36) = False Then
           
    Controller.Switch(36) = True
       
    End If
       
    If Controller.Switch(36) = True Then
           
    Controller.Switch(36) = False
       
    End If

    jabdoa

    unread,
    Apr 18, 2020, 6:28:36 PM4/18/20
    to MPF Users
    I don't think we got debounce for VPX at all yet. Should we add that? Not sure if that is needed generally.


    Jan

    atum

    unread,
    Apr 18, 2020, 8:20:34 PM4/18/20
    to MPF Users
    I would lean towards no.  I think if you account for it with the code above it does everything you need.  Plus if you go into the debug mode during a game, its easier.  Clicking on "hit" does both the hit and unhit event, so it "resets" the target, rollover, etc. for the next round.  If you don't do the code that I showed above, you have to click hit, then click unhit.  So its two inputs versus one during debug.

    I have on my list of things for the week to get through the updated help pages for VPX in the MPF docs.  So I will need to create some new pages to boost up the piece, and will add in examples for everything that I have done in mine, including this to help it make sense out of the box.
    Reply all
    Reply to author
    Forward
    0 new messages