Aego Русский

aego/timer

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.

On this page

Example

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")
    }
}

Functions

Cooldown(seconds float) Handle<aego/timer.Timer>Makes a timer that starts ready; Use takes it and starts the wait.
New(seconds float) Handle<aego/timer.Timer>Makes a timer that stays after it ends, so Restart can run it again.
Start(seconds float) Handle<aego/timer.Timer>Makes a one-shot timer that frees itself when it fires.
TimerTimer counts down and fires. yield t waits for the next fire or the end; a timer dies with the node of the script that made it.

Cooldown function

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

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

Example

if attack.Use() {
	fire()
}

New function

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

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

Example

spawn = timer.New(3).Repeat(-1)

Start function

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

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

Example

yield timer.Start(0.5)