# Startclock

A "starting clock", like an ALGE ASC3, can be shown with RRExchange.&#x20;

RR12 needs to have an output list containing the next starttime and the bib and name of the athlete to start. RRExchange will periodically pull this list via it's [Globals ](https://docs.dbnetsoft.com/dbnetsoft/raceresultexchange/scripting/globals)feature. Then you can use any of the pre-defined template and use it for displaying these values.&#x20;

## Prepare RR12

Create an output list named `StartClockTest` with the folliwng fields:

| Column Name   | Description                                      |
| ------------- | ------------------------------------------------ |
| CurrentTime   | not needed but good to see if we receive changes |
| NextStarttime | start time of next athlete to start              |
| NextBib       | bib of next athlete top start                    |
| NextName      | name of next athlete to start                    |

Set the Maximum number of records to only 1.

<figure><img src="https://2601835662-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fk5GLs0WFtuWoGrMBjgcM%2Fuploads%2FK7bn2YIXyIcxndFu4wKT%2Fimage.png?alt=media&#x26;token=f587973b-702b-4d1c-876e-99f002f632da" alt=""><figcaption></figcaption></figure>

## Prepare RRExchange

### Globals

Click on Globals in the top center of the window, then click on RaceResult 12 Lists and add a new entry called StartClockTest and assign the newly created output list.

<figure><img src="https://2601835662-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fk5GLs0WFtuWoGrMBjgcM%2Fuploads%2FaDiwj4M6CvclZslCKHsa%2Fimage.png?alt=media&#x26;token=2a1ac80c-eabb-485f-be75-5c36acb9881b" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
If you do not see the newcly created output list, close the Globals window and click on the refresh button next to the event name. This will query all list names again.
{% endhint %}

## Scripting

Bring up the scripting window for the Clear template and remove all existing content. In order to check the retrieveal of the output list, write the following content:

```
{{ StartClockTest.First.CurrentTime }}
```

You should then see a clock, which is generated by the RR12 output list.&#x20;

If so, remove all of it and replace it with this code:

```
{{
     # Check for any scheduled at all (either no row at all or empty starttime)
     if (StartClockTest.First != null && StartClockTest.First.NextStarttime != "")
       # Get current time
       now = Clock
        # Convert time of day to time span
       starttime = ToDateTime StartClockTest.First.NextStarttime
       # Calculate remaining time to start
       timeRemaining = datetime.Subtract starttime now       
       
       # Output string including bib number
       StartClockTest.First.NextBib + " -> " + timespan.FormatRaceResult timeRemaining "mm:ss"       
    else 
         "No one scheduled"
    end
}}
```

<figure><img src="https://2601835662-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fk5GLs0WFtuWoGrMBjgcM%2Fuploads%2FkaWR1Kcqs6zHVaQ0Eaxk%2Fimage.png?alt=media&#x26;token=fb0850eb-52c9-4c61-8f5f-955c90260e71" alt=""><figcaption></figcaption></figure>

From here on you can add different colors based on the time remaining or clamp the time at 0.
