# Coming from Defold

Defold is the closest starting point: small games, Lua scripts and messages between
objects. Coldwave's scripts are Luau, a descendant of Lua, so most of your code reads the
same. The calls into the engine change, state moves out of `self`, and every run replays
exactly. There is no importer for Defold projects yet: you rebuild collections by hand or
with an AI agent, and much of your Lua carries over line by line.

## What maps to what

| Defold | Coldwave |
| --- | --- |
| Collection | A scene: a TOML file of named things and their components ([scenes](../concepts/scenes.md)) |
| Game object | A thing: a number with an optional name, made of components ([things](../concepts/things.md)) |
| Sprite, collision object | Components: `Sprite`, `Body`, `Collider` |
| `go.property` | Your own component under `[components]` in `game.toml`, or `[tuning]` numbers |
| `update(self, dt)` and `fixed_update` | One `step(dt)`, called 60 times a second at a fixed step |
| `init(self)` | `on_scene(name)`, called when a scene has started |
| `msg.post` and `on_message` | `send("hit", thing, 1)` in one script, `events("hit")` in another |
| `self` | Components on the thing, or the script's `state` table |
| `go.get_position()`, `go.set_position()` | `get(thing, "Transform", "x")`, `set(thing, "Transform", "x", value)` |
| Factory | `spawn(...)` with the components the new thing starts with |
| Collection proxy | `scene.load("level2.toml")` |

## Movement

A thing that slides right at its own speed. In Defold:

```lua
go.property("speed", 90)

function update(self, dt)
    local p = go.get_position()
    p.x = p.x + self.speed * dt
    go.set_position(p)
end
```

In Coldwave, with `Slider = { speed = 90.0 }` under `[components]`:

```lua
function step(dt)
    for _, thing in ipairs(each("Slider", "Transform")) do
        local x = get(thing, "Transform", "x")
        set(thing, "Transform", "x", x + get(thing, "Slider", "speed") * dt)
    end
end
```

## Messages become events

In Defold:

```lua
msg.post("/score", "picked", { value = 5 })
```

In Coldwave, the event is read in the same step by any script:

```lua
send("picked", coin, 5)

for _, picked in ipairs(events("picked")) do
    state.score += picked.value
end
```

## What carries over

- **Your Lua.** Tables, functions, loops and most helpers work as they are. Luau adds
  optional types and a few conveniences such as `+=`.
- **Messages.** Events play the same role, and they are part of the replay.
- **Your art.** PNG pictures, glTF models with their clips, WAV sounds and OGG music. JPEG
  is not read yet, so convert those to PNG.

## What changes

- **`self` is not memory.** Keep what the game must remember in components or in `state`.
- **One script walks many things.** Scripts run once a step and find their things with
  `each`.
- **Positions are fields.** `Transform` has `x`, `y` and, in 3D, `z`, read and written one
  at a time.

## Next

[Your first game](../start/first-game.md) takes about ten minutes.
[Steps and determinism](../concepts/steps.md) explains why every run replays.
