# Running Tally in Shortcuts (or Drafts)

The ultimate question I’m asking here is whether it’s possible to do some basic math functions to keep a running total using Shortcuts or Drafts. Here’s the use case I’m trying to solve…

I cover high school sports events in my hometown. For basketball, I use Drafts to keep a running tally of the score. I’d like to automate some of the typing and calculation if I can.

I use this tally to re-create the scoring ebbs and flows after the game when I am writing my story. Here’s what my Drafts document looks like (with a brief description to follow):

2-0 Smith 2
2
4 Smith 4
6 Jones 2
8 Smith 6
11 Jefferson 3
14 Smith 9
4

After the game, I can glance at this and see how the game unfolded. Above, the hometown team went ahead 2-0, then the opposing team tied the game 2-2. Then the hometown team scored 12 straight points before the opposing team scored again. (The score is 14-4 at the point where the example stops.)

The hometown team’s scores are not indented. The opposing team’s scores are indented slightly. I note which player scored (only when it’s the hometown team), and keep a running tally of that individual player’s scoring total. (In the example above, Smith has 9 points, Jefferson has 3, and Jones has 2.)

I’ve created a shortcut that adds a new line to a Drafts document each time a team scores, but I wonder if there is a way to have Drafts or Shortcuts to the calculation of the running total by parsing out the previous score. Ideally, I’d love to input that Team A scored 2 points, choose the player who scored from a list, and have that 2 points added to both the running team points total AND the individual player’s scoring total.

Right now, my shortcut asks me how many points were scored, which team scored them, asks me the player name (chosen from a list of players on the home team’s roster), and asks for the NEW point total for the team that scored. Is it possible to use the shortcut or Drafts to make that math happen?

In short, yes.

Drafts’ Javascript based scripting actions can parse the content of a draft, extract numeric values based on position, calculate the details and append the result along with any appropriate text.

You could do it with Shortcuts, but it would mean round tripping and quite honestly it would probably be easier to work with the text and maths functions in Drafts assuming you are familiar with Javascript. If you’re not, an don’t fancy becoming familiar, then Shortcuts may be a more practical option for you.

However…

It looks like you are actually writing a little database. Drafts may not be the best option for that.

Shortcuts and saving data to files (potentially in JSON format for easier access and updating of data items) might be a good approach, but then the data isn’t quite so readable and you’ll either end up with some cumbersome files as you record more and more games, or lots and lots of separate files that might get hard to keep track of.

For that reason I’m wondering if Airtable, an actual database platform, might be a better option for you to consider? You could build your database with the iOS app and if needs be you could build some quick entry tools using Shortcuts. It’s perhaps more effort than you might first have considered, but with a database approach you could open yourself up to working with stats in other ways which I think is always a win when dealing with sports.

Hope that helps.

1 Like

This is great. Thank you! I had actually thought about AirTable, but. I’ve never used it so I wasn’t sure. I may have to dig around and see what I can accomplish. Thanks for the nudge!