Count Actions Based on Active 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:

Look at data collected within a specific period of play (e.g., full games, halves, quarters, periods, etc.)


Example Used:

In this example we use halves to demonstrate how utilizing toggle buttons can simplify your analysis of data. We measure field goals made (FGM), field goals attempted (FGA) and field goal percentage (FG%) for a basketball team. This concept can be applied to any sport or type of period of play (e.g., quarters, periods, innings, etc).


Commands Used:

  • Button IDs
  • OR
  • Count Instances
  • Show
  • Button State
  • If (Statements)

All instances need a label that indicates the specific period of play. Learn more about labeling your instances.


How To:

  1. Create three toggle buttons:

    • Button 1 - titled "Full Game"
    • Button 2 - titled "1st Half"
    • Button 3 - titled "2nd Half"

    To create a toggle button, open the inspector for each button and change Button type to Action. Then change Action (dropdown) to Toggle.

  2. Open the inspector for each player. Add a button ID.

    Each player needs to have a button ID for the scripts to work.

  3. Open the inspector for the FGM button for player 1. Navigate to the Script tab and add the following script:

    $player = #”p01”
    Refers to the Button ID of player 1. This will pull any information that is related to the name of that button. Change the information inside the quotes to match your Button ID.

    $fgm = “Make 2 Pts” OR “Make 3 Pts”
    Sum of all the shots made.
    OR is a logic command that combines labels that are referenced in the command.
    Change “Make 2 Pts” and “Make 3 Pts” to match your labels. (Must remain in quotes.)

    $fga = “Make 2 Pts” OR “Make 3 Pts” OR “Miss 2 Pts” OR “Miss 3 Pts”
    Sum of all shots.
    OR is a logic command that combines labels that are referenced in the command.
    Change “Make 2 Pts” etc. to match your labels. (Must remain in quotes.)

    $half = (“1st Half” OR “2nd Half”)
    This variable considers all the labels with the 1st Half or the 2nd Half tagged. If no button is active, the output result will be reflective of the whole game.

    IF (BUTTON "1st Half" STATE = 1, $half = “1st Half”)
    This if statement will check if the button “1st Half” is active, if it is it will change the name of the variable $half to “1st Half”.

    IF (BUTTON "2nd Half" STATE = 1, $half = “2nd Half”)
    This if statement checks if the button “1st Half” is active. If it is active, it will change the name of the variable $half to “2nd Half”.

    IF (BUTTON "Full Game" STATE = 1, $half = (“1st Half” OR “2nd Half”))
    This if statement will check if the button “Full Game” is active. If it is active, it will change the name of the variable $half to (“1st Half” OR “2nd Half”).

    $result = $fgm and $half where row = $player
    This variable considers all the instances that have the labels contained in the variable $fgm together with the ones in the variable $half and belong to the row with the name of the player of the variable $player, in this example “Chris Hansen” as he has ID = p01.

    show count $result
    The count command will allow us to count the instances found in the variable $result. We will be able to display it with the help of the show command.

    show $result
    The show command will show the video of the instances found in the variable $result.

  4. Repeat steps for each statistic, changing the labels to reflect the statistic you're looking for.