Skip to content

Learn Lua

Lesson 1.1

Learn Lua from zero, then use it to make your own Celestial mods. No programming experience needed.

Lua is a small, friendly language. It has few rules and they fit together well, so you can learn the whole language in a few evenings. Celestial runs Lua mods directly: you save a file and the game picks up the change, with no compiler and no build step.

How the course works

The course has two parts.

Part 1: the Lua language

Everything Lua can do, from your first print to metatables and coroutines. The examples are plain Lua and run anywhere.

Part 2: making mods

The Celestial API in Lua: setting up a mod, events, items and blocks, commands, screens, networking, and publishing.

Part 1 has seven chapters:

  • Getting started. What Lua is and how to run it.
  • The basics. Values, variables, numbers, strings and logic.
  • Control flow. if, else and loops.
  • Functions. Writing your own, returning several values, closures.
  • Tables. Lists, dictionaries, the table library and modules.
  • Metatables and objects. Custom behaviour, classes and inheritance.
  • Going further. Errors, coroutines, string patterns, the standard library and good habits.

Part 2 has nine chapters:

  • Your first mod. The SDK, the manifest, running the game with your mod and hot reload.
  • Events. Listening, changing and cancelling, and the list of every event.
  • Players and text. Player properties, giving items, messages, colours and translations.
  • Items and blocks. Registering content, assets, recipes, reading and placing blocks, entities (spawning, moving, your own types), models and animation for them, entity gameplay (finding, buffing, hurting, spawning, riding), world access (ray casts, bulk reads, properties, containers) player control (movement, model parts, locks, food), and AI (paths, goals) and saved data (on mobs, players, chunks and the world).
  • Commands and timers. Commands with arguments, waiting and repeating, config files.
  • The client. Client and server, keybinds, the HUD, screens and menus, sound and music, particles, post effects, the camera, themed GUIs with HUD elements and Appearance pages, React-style components, and HTML/CSS overlays and panels.
  • Networking and permissions. Messages between client and server, the sandbox’s capabilities, and your own files and websites.
  • Finishing up. Debugging, publishing on the Celestial website, and a complete project.
  • Mixins. Hooking into the game’s own code: head, return, points, values, wraps, invokers, priorities and debugging, with a project.

If you already know Lua, you can start part 2 right away with Setting up.

Every lesson has the same shape

  • A short explanation with small examples you can run.
  • Try it: a small exercise. Write the code yourself before you open the solution.
  • Recap: the lesson in one line.

In part 2, the examples use the game API, so they run inside the game rather than on their own. Each lesson says what to expect when you try them.

The examples show what they print with a --> comment:

print(2 + 3)  --> 5

You don’t type the --> part. It just tells you what to expect.

Type the examples

Reading code is not the same as writing it. Type the examples yourself, change them, and break them on purpose. Error messages are much less scary once you have caused a few.

Start with What is Lua?