Perform an Operation with the Output of Two Buttons

This tutorial is specific to our newest product, Hudl Sportscode. If you’re on Sportscode v11, use these resources instead or upgrade today.

Desired Outcome:

Perform a mathematical calculation with the output of two different buttons.


Example Used:

In this example, we will show the points scored by two different players and the sum of them in a third button.


Commands Used:

  • Show count
  • @”button_id”

How-to:

  1. Create two inactive buttons:

    • Button 1 - titled "Pts1" and button ID "P1"
    • Button 2 - titled "Pts2" and button ID "P2"
  2. Open the inspector for the first button and navigate to the Script tab. Add the following script:

    show count "Point" where row = "Player1"

    This counts how many “Point” labels are in the “Player1” row and shows the result.

  3. Open the inspector for the second button and navigate to the Script tab. Add the following script:

    show count "Point" where row = "Player2"

    This counts how many “Point” labels are in the “Player2” row and shows the result.

  4. Create a third inactive button. Open the inspector and navigate to the Script tab. Add the following script:

    $P1 = @"P1"
    Using the "P1" command, the $P1 variable will get the output of the button whose ID = P1.

    $P2 = @"P2"
    Using the "P2" command, the $P2 variable will get the output of the button whose ID = P2.

    $Total = $P1 + $P2
    The $Total variable will store the sum of the values of buttons P1 and P2, represented by their variables.

    show $Total
    This command will show the result of the sum.