# Overview

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

This page reads one complete script: an enemy that walks back and forth, waits at each end and tells other scripts when it turns. Each part links to the page that explains it.

```aes run
package enemy

import "aego/log"

enum State {
    Walk
    Wait
}

script Patrol {
    @export(min=0, max=20, unit="u/s")
    var Speed float = 3

    @export(min=0, max=50, unit="u")
    var Distance float = 4

    @export(min=0, max=5, unit="s")
    var Pause float = 0.5

    signal Turned(dir float)

    var state State
    var dir float = 1
    var origin float
    var turns int

    func Ready() {
        origin = node.Position().X
        Turned.Connect(OnTurned)
    }

    func Update(dt float) {
        if state == State.Wait {
            return
        }
        p := node.Position()
        p.X += dir * Speed * dt
        node.SetPosition(p)
        if dir > 0 && p.X >= origin+Distance || dir < 0 && p.X <= origin {
            start Turn()
        }
    }

    func Turn() coroutine {
        state = State.Wait
        yield wait(Pause)
        dir = -dir
        sr := node.Get<SpriteRenderer>()
        if sr != nil {
            sr.FlipX = dir < 0
        }
        state = State.Walk
        Turned.Emit(dir)
    }

    func OnTurned(d float) {
        turns++
        log.Info("turn " + string(turns) + ", walking " + string(d))
    }
}
```

## The parts

- `package enemy` and `import` name the script's package and the engine packages it uses. See [Files and packages](/language/files-and-packages.md).
- `enum State` declares the two states. See [Types](/language/types.md).
- `@export` shows `Speed`, `Distance` and `Pause` in the Inspector, with their range and unit. See [Attributes](/language/attributes.md).
- `Ready` runs once when the node enters the game, `Update` once per frame. See [Scripts and lifecycle](/language/scripts-and-lifecycle.md).
- `node` is the node the script is attached to; `node.Get<SpriteRenderer>()` reads one of its components. See [Nodes, components and references](/language/nodes-components-and-references.md).
- `Turn` is a coroutine: `yield wait(Pause)` pauses it for `Pause` seconds without stopping the game. See [Coroutines](/language/coroutines.md).
- `signal Turned` lets other scripts react to the turn. The script connects its own handler to it in `Ready` and emits it at the end of `Turn`. See [Signals](/language/signals.md).

## Using it

1. Save the script as `scripts/enemy/patrol.aes`.
2. Select a node with a sprite, press **Add Script** in the Inspector and pick **Patrol**.
3. Press Play. The node walks right, waits, turns and walks back.
4. While the game runs, change **Speed** or **Distance** in the Inspector. The node follows the new values at once.
