# aego/timer

> Aego 0.12.5 · development; docs build `4a32b816933e02930662f6a443cb25abe6050d090c55e237cbff5c44ae9b25f8`. [Build manifest](/docs-build.json).

A timer belongs to the node of the script that made it and is cancelled when that node is destroyed. `yield t` waits for the next fire, and `Fired` runs on every fire. See [Timers](/tween/timers.md).

## Example

```aes run
package demo

import (
    "aego/log"
    "aego/timer"
)

script Turret {
    var reload timer.Timer
    var waves timer.Timer
    var shots int

    func Ready() {
        reload = timer.Cooldown(0.3)
        waves = timer.New(0.5).Repeat(3)
        waves.Fired.Connect(OnWave)
        start Countdown()
    }

    func Update(dt float) {
        if reload.Use() {
            shots++
        }
    }

    func OnWave(count int) {
        log.Info("wave " + string(count) + ", shots so far " + string(shots) + ", reload ready in " + string(reload.Remaining()))
    }

    func Countdown() coroutine {
        yield timer.Start(1.8)
        log.Info("waves done: " + string(waves.Done()) + ", fired " + string(waves.Count()) + " times")
    }
}
```

## Cooldown

```
func Cooldown(seconds float) Handle<aego/timer.Timer>
```

Makes a timer that starts ready; Use takes it and starts the wait.

## New

```
func New(seconds float) Handle<aego/timer.Timer>
```

Makes a timer that stays after it ends, so Restart can run it again.

## Start

```
func Start(seconds float) Handle<aego/timer.Timer>
```

Makes a one-shot timer that frees itself when it fires.
