Count Actions that Occur in a Specified Time Range
Example Used
In this example we want to count the number of ‘Team 1 Shots’ that were ‘On Target’ in the first, second & third minutes of a coded event.
Commands Used
- Variables
- Count
- Or
- Start Time
- Show Count
- Show
How-to:
-
Create one CODE BUTTON and two LABEL BUTTONS that will be used to test your scripting:
- CODE BUTTON – Name this ‘Team 1 Shots’ with a button ID of #’team1_shots’
- LABEL BUTTON 1 – Name this ‘On Target’ with a button ID of #’on_target’
- LABEL BUTTON 1 – Name this ‘Off Target’ with a button ID of #’off_target’
To speed up your coding, use an activation link from each label button to the ‘Team 1 Shots’ code button.
-
Create two buttons that will count the number of times ‘Team 1’:
- Has a shot on goal (TOTAL SHOTS)
- Has a shot on goal that was ‘On Target’ (TOTAL SHOTS On Target)
-
The ‘TOTAL SHOTS’ counter button requires the following script:
$a = #"team1_shots"
$chance = #"on_target" or #'off_target' WHERE ROW = $a
show count $chance
show $chanceThe ‘TOTAL SHOTS On Target’ counter button requires the following script:
$a = #"team1_shots"
$chance = #"on_target" WHERE ROW = $a
show count $chance
show $chance -
Create three Buttons (numbered 3, 4 & 5 in the image below) as follows:
- 1st Minute – This will count actions between 0 - 1 minutes.
- 2nd Minute – This will count actions between 1 - 2 minutes.
- 3rd minute – This will count actions between 2 - 3 minutes.
If you are using a PRO license these buttons can be inactive. If you are using an ELITE license, these buttons should be ACTION (make movie).
-
The above buttons should be scripted as follows:
Button 3: 0-1 minute
$a = #"team1_shots"
$chance = #"on_target" WHERE ROW = $a and start time <=60
show count $chance
show $chanceButton 4: 1-2 minutes
$a = #"team1_shots"
$chance = #"on_target" WHERE ROW = $a and start time >=61 and start time <=120
show count $chance
show $chanceButton 5: 2-3 minutes
$a = #"team1_shots"
$chance = #"on_target" WHERE ROW = $a and start time >=121 and start time <=180
show count $chance
show $chanceHudl Sportscode script calculates time using seconds (e.g., 1 minute = 60, 5 minutes = 300, 15 minutes = 900, etc.)
You are now ready to calculate identified instances or labels that occur during a given time period.