Tutorial 15: Add scoring - The Mission Pinball Framework (2024)

This is part of our Getting Started guide.

The guide starts here.

It's been awhile since this tutorial has been updated. If you find anything that is no longer relevant, please let us know, or better yet, edit or update it yourself!

By now you have a "playable" game with a base game mode, and you'vegot a score showing on the display, but it's still pretty boring sincenothing is actually configured to register a score yet. So in this stepwe're going to add some scoring.

1. Understand how scoring works in MPF

MPF includes a core module called the Variable Player which isresponsible for adding (or subtracting) points from a player's score.Actually, that's not a completely accurate description. We shouldreally say that the variable player is responsible for adding orsubtracting value from any player variable. (A player variable is just akey/value pair that is stored on a per-player basis.) The score is themost obvious player variable. But MPF also uses player variables totrack what ball the player is on, how many extra balls the player has,etc. You can create player variables to track anything you want. Rampsmade, combos made, number of modes completed, aliens destroyed, etc.

The variable player is responsible for adding and subtracting value fromany player variable based on events that happen in MPF. You configurewhich events add or subtract value to which player variables in thevariable_player: section of a mode's configuration file.

2. Add a variable_player: section to your base.yaml mode config file

The first step is simply to add a variable_player: section to yourbase mode's base.yaml config file. So in this case, that will be<your_machine>/modes/base/config/base.yaml. Add a new top levelconfiguration item called variable_player:, like this:

variable_player:

3. Add point values for events

Then inside the variable_player: section, you create sub-entries forMPF events that you map back to a list of player variables whose valueyou want to change. By default, whenever a switch is hit in MPF, itposts an event (switch_name)_active . (A second event called(switch_name)_inactive is also posted when the switch opens backup.) To give the player points when a switch is hit, add sub-entries tothe variable_player: section of your config file, with some switchname followed by "_active", like this:

##! mode: basevariable_player: s_right_inlane_active: score: 100 s_left_flipper_active: score: 1000

Now save your config, start a game (S), hit the L key to launch aball, then hit the Q key to trigger the right inlane switch . Youshould immediately see a score of 100 points. Then if you hit the Zkey for the left flipper, you'll see the player's score increase by1000 points. You can hit it as many times as you want to see the scoreincrease:

Remember from the previous step that the slide_player: section of theconfig contains a text widget with a value of (score) in parentheses,and any values in parentheses are updated automatically when theunderlying player variable changes. So that's how the display isupdating automatically here.

By the way, there's areference list of many built-in events in the documentation, so you can browse through that to getan idea of the various types of events that exist which you can use totrigger display slides or score events.

Note that variable_player: events in a mode's config file are onlyactually active when that mode is active. So the section we're addingin this step is in the base mode's config, which we've set to startany time a ball starts. But if the base mode ever wasn't running, thenthe s_right_inlane_active and s_left_flipper_active events wouldn'ttrigger a score.

When you create more modes in the future, you can actually configurethat a score event in a higher-priority mode "blocks" thevariable_player/scoring event in a lower-priority mode. So you couldhave a pop bumper that is worth 100 points in a base mode, but then youcould also make it worth 5,000 points in a super jets mode whileblocking the 100 point score from the base mode since if the scoringfrom both modes was active, you'd get two scoring events--the 100 fromthe base mode and the 5,000 from the super jets mode. (More on thatlater.)

Later on you can also configure shots which can control lights andmanage sequences of switches and lots of other cool things, so that'show you can track the ball moving left-to-right or right-to-left arounda loop, and from there you'll be able to configure different scoringevents for each direction. (Again, we'll get to this later. For now youcan just wire up scoring to a switch to see it working.)

4. Play with more player variables

As we said, you can add or subtract value from any player variable viathe variable_player: section--even player variables that you make up.

For example, try changing your scoring section to this:

# we will initially set the value to 0 when the machine starts upplayer_vars: potato: initial_value: 0##! mode: base# in your base mode (modes/base/config/base.yaml)variable_player: s_right_inlane_active: score: 100 s_left_flipper_active: score: 1000 potato: 1 s_right_flipper_active: potato: -2

We use the word "potato" here to illustrate that player variables canbe anything. So now when the left flipper is active, the player variablecalled "score" will increase by 1000, and the player variable called"potato" will increase by one. (If you make a reference to a playervariable that hasn't been defined before, it will automatically becreated with a value of 0.)

Also notice that when the right flipper is hit, the player variablecalled "potato" will have a value of 2 subtracted from it.

Player variables exist and are tracked even if they're not displayedanywhere. So if you run your game now and start flipping, the potatovalue will change. Again, player variables are stored on a per-playerbasis, so if you start adding additional players to the game, they'lleach have their own copies of their own player variables. Also theplayer variables are destroyed when the game ends. (It is possible tosave certain variables from game-to-game, but we'll discuss thoselater, as those are not player variables.)

So now that we're tracking this potato variable, let's add it to thedisplay. To do this, let's add another widget to the slide that is showwhen the base mode starts. (So we're going to be editing<your_machine>/modes/config/base.yaml again. Add the potato textentry, like this:

#! player_vars:#! potato:#! initial_value: 0##! mode: base# in your base mode (modes/base/config/base.yaml)slide_player: mode_base_started: widgets: - type: text text: (score) number_grouping: true min_digits: 2 font_size: 100 - type: text text: PLAYER (number) y: 10 x: 10 font_size: 50 anchor_x: left anchor_y: bottom - type: text text: BALL (ball) y: 10 x: right-10 anchor_x: right anchor_y: bottom font_size: 50 - type: text text: 'POTATO VALUE: (potato)' y: 40%##! test#! start_game#! start_mode base#! advance_time_and_run .1#! assert_text_on_top_slide "PLAYER 1"#! assert_text_on_top_slide "BALL 1"#! assert_text_on_top_slide "POTATO VALUE: 0"

Notice that we put text: 'POTATO VALUE: (potato)' in quotes. That'sbecause we actually want to show the colon as part of the text that'sdisplayed on the screen. However colons are important in YAML files. Soif we made our entry like this: text: POTATO VALUE: (potato), then wewould get a YAML processing error because the YAML processor would freakout. "OH MY THERE ARE TWO COLONS?? WHAT'S THIS MEAN??? "

So we use quotes to tell it that the second colon is just part of ourstring.

Now you can run your game (via mpf both), S to start a game, L tolaunch a ball, then use the Z and / keys to left and right flip whichwill adjust the potato value accordingly.

Notice that when you first start a game, the onscreen text saysPOTATO VALUE: (potato). That's because when this slide is firstdisplayed, there is no player variable called "potato"--it's notcreated until you hit a flipper button--so the text widget doesn'tknow what to do with "potato", so it just prints it as is. Laterwe'll learn how to properly initialize variables, but the main thingfor now is to see how the scoring and slide player works.

Check out the complete config.yaml file so far

If you want to see a complete config.yaml file up to this point, it'sin the mpf-examples/tutorial/step_15 folder with the nameconfig.yaml. You can run it be switching to that folder and runningmpf both:

C:\mpf-examples\tutorial_step_15>mpf both

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
Tutorial 15: Add scoring - The Mission Pinball Framework (2024)

References

Top Articles
20 Work-From-Home Job Scams and How to Spot Them
20 Common Job Search Scams and How to Protect Yourself
Pollen Count Los Altos
DPhil Research - List of thesis titles
Big Spring Skip The Games
CA Kapil 🇦🇪 Talreja Dubai on LinkedIn: #businessethics #audit #pwc #evergrande #talrejaandtalreja #businesssetup…
Optum Medicare Support
New Day Usa Blonde Spokeswoman 2022
Violent Night Showtimes Near Amc Fashion Valley 18
Derpixon Kemono
Blue Ridge Now Mugshots Hendersonville Nc
Dexter Gomovies
Best Suv In 2010
Nba Rotogrinders Starting Lineups
Wal-Mart 140 Supercenter Products
How Much Is Tay Ks Bail
97226 Zip Code
Delaware Skip The Games
Happy Life 365, Kelly Weekers | 9789021569444 | Boeken | bol
Shadbase Get Out Of Jail
Wisconsin Volleyball Team Boobs Uncensored
Lovindabooty
Harbor Freight Tax Exempt Portal
10-Day Weather Forecast for Santa Cruz, CA - The Weather Channel | weather.com
950 Sqft 2 BHK Villa for sale in Devi Redhills Sirinium | Red Hills, Chennai | Property ID - 15334774
Guide to Cost-Benefit Analysis of Investment Projects Economic appraisal tool for Cohesion Policy 2014-2020
134 Paige St. Owego Ny
Ilabs Ucsf
Math Minor Umn
Kattis-Solutions
Gideon Nicole Riddley Read Online Free
Chattanooga Booking Report
One Credit Songs On Touchtunes 2022
Metro 72 Hour Extension 2022
Zero Sievert Coop
Gun Mayhem Watchdocumentaries
Indio Mall Eye Doctor
Infinite Campus Farmingdale
Owa Hilton Email
Lucyave Boutique Reviews
Panolian Batesville Ms Obituaries 2022
Dickdrainersx Jessica Marie
Silicone Spray Advance Auto
Bekkenpijn: oorzaken en symptomen van pijn in het bekken
White County
Port Huron Newspaper
Iron Drop Cafe
Model Center Jasmin
What Time Do Papa John's Pizza Close
Psalm 46 New International Version
Kobe Express Bayside Lakes Photos
Obituaries in Westchester, NY | The Journal News
Latest Posts
Article information

Author: Geoffrey Lueilwitz

Last Updated:

Views: 6266

Rating: 5 / 5 (60 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Geoffrey Lueilwitz

Birthday: 1997-03-23

Address: 74183 Thomas Course, Port Micheal, OK 55446-1529

Phone: +13408645881558

Job: Global Representative

Hobby: Sailing, Vehicle restoration, Rowing, Ghost hunting, Scrapbooking, Rugby, Board sports

Introduction: My name is Geoffrey Lueilwitz, I am a zealous, encouraging, sparkling, enchanting, graceful, faithful, nice person who loves writing and wants to share my knowledge and understanding with you.