# Variables

Variables can be used without any config — undeclared variables are auto-created with `deck` lifetime (reset each session):

```lua
castle.setVariable("score", 100)
local score = castle.getVariable("score")
```

To use **user-lifetime** variables (persist across sessions) or **ticker** variables (global leaderboard counters), declare them in `castle-script.json`:

```json
{
  "variables": [
    { "name": "score",     "initialValue": 0, "lifetime": "deck" },
    { "name": "highScore", "initialValue": 0, "lifetime": "user" },
    { "name": "topScore",  "initialValue": 0, "lifetime": "ticker" }
  ]
}
```

- `"deck"` — resets each game session (default if not declared)
- `"user"` — persists per user to the server (requires running in the Castle app)
- `"ticker"` — global server-synced counter; supports `castle.updateTicker("topScore", 1)`
