Scripting
Code window and Text to Code
The Code window
Code > Code Editor, or double-click a .lua file in Assets.
- Tabs, Lua syntax highlighting and a monospace font.
- Errors as you type: the line of a syntax error is marked, and the status bar says what's wrong.
- Autocomplete (Ctrl+Space) for Lua and the whole Ember API, and hover help that shows a function's arguments and what it does.
- Find and replace, and an Insert menu with every API call.
- Ctrl+S saves. While the game is playing, saving reloads the script in the running game (objects keep
their
self.*state). If the new code has an error, the old code keeps running. - Closing a tab with unsaved changes asks whether to save them.
New Script
Code > New Script… makes a script from a template and can attach it to the selected object:
| Template | What it does |
|---|---|
| Empty behaviour | start and update, nothing else |
| Player controller | WASD / stick to walk, Space to jump, with a physics body |
| Follow camera | a third-person camera that follows an object |
| Collectible | spins, bobs, disappears and scores when the Player touches it |
| Enemy chase | walks towards the Player when it is close |
| Door / trigger zone | opens (moves up) while something stands in the zone |
| Spawner | creates a falling crate every few seconds |
| HUD | score and timer on screen |
| Terrain digger | click the ground to dig, Shift+click to build up |
Text to Code
Code > Text to Code…: type what should happen in English and see it three ways:
- Graph: a flowchart of events, steps and yes / no / loop branches. Each step shows how confident the parser is.
- Steps: your words, what each became, its confidence, and the other readings it considered.
- Lua: the code it compiles to.
Save as Blocks or Save as Lua writes it into scripts/ (with a new name if that file already
exists) and can attach it to the selected object.
It uses the same offline, rule-based parser as Write it in words, so it can be inaccurate. Read the steps before relying on them.