Scripting overview
The ways a mod adds behaviour - QuestScript and Pawn for levels, Lua for heroes, skills, items, creatures and game modes, traits, and blueprints that write either - and which to use for what.
Much of what a mod changes is data: numbers, items, creatures, skills made in the Skill Designer. When a mod needs behaviour no data covers, it adds a script. The game runs three languages, and the devkit can write two of them for you as node graphs.
| Language | Runs | Good for | Page |
|---|---|---|---|
| QuestScript | A level's script: its quests, dialogs, triggers, waves and doors | Changing a disc level's story, scripting a custom map | QuestScript |
| Pawn | Level scripts, and game scripts for the whole game | The same as QuestScript and Lua game scripts, for those who know Pawn | Pawn scripts |
| Lua | Hero scripts (classes, races, skills, items, bonuses, traits), monster scripts and game scripts | Passives, scripted skills, gear rules, creature tricks, game modes | Lua scripts |
| Blueprints | Node graphs compiled to QuestScript (level scripts) or Lua (hero scripts) | The same, without writing code | Blueprint Editor |
Traits are named Lua scripts with parameters that races and classes list, and the way to make gameplay rules every hero has: see Traits.
Which to use
- A level's story (a quest, a dialog, a door that opens when the orcs are dead): the level's script, in QuestScript or Pawn, edited in the Script Editor. Start by converting the disc's script.
- A class or race passive (more damage after a kill, regeneration, no shields): a Lua hero script, usually as a trait.
- A new skill: try the Skill Designer first. Write a Lua scripted skill when no kind covers
it, or a
customdesign whose script does what it does. - An item or bonus that does something (a ring that heals on kills): a Lua script named by the item or the bonus (see Items).
- A creature with a trick (a shaman that heals its friends): a Lua monster script.
- A game mode (bounties, waves, kill streaks): a game script under
scripts/game/, in Lua or Pawn.
Where scripts live
| File | Is |
|---|---|
scripts/**/*.lua |
Lua scripts. Named by what runs them (a class's script, a creature's script...). |
scripts/game/*.lua, scripts/game/*.pwn |
Game scripts: they run by themselves |
BG/DATA/<LEVEL>.GOB/<lump>.lmp/script.qs |
A disc level's script, replacing the disc's |
maps/<id>.qs |
A custom map's script |
assets/graphs/<name>.rgraph |
A blueprint, and the script file it writes |
How each kind of script is named and attached, and how the editors do it for you, is in Attaching scripts.
Scripts and online games
Lua scripts and game scripts run only where the game's simulation runs: on a single machine, or on the host of a network game. Other players see their results, so they never need syncing. Each language's sandbox makes scripts give the same results everywhere: random numbers come from the game's own generator, and anything that could differ between machines (files, the clock, the order of a table walk) is fixed or left out.
Level scripts run on every machine, as the disc's do.
A script that errs is logged, and that call has no effect: one broken script doesn't stop the game. Watch the log while you test (see Testing).
