Forge Setup: OCaml on Your Machine

The in-page engine is a fine training sword, but real games need a real forge: today you install the OCaml toolchain on your own machine, build the starter game, and watch it bounce at localhost:8000.

You will be able to…

Meet the crew

Why leave the browser at all? Because the page engine, honest as it is, can't build multi-file projects, can't read files, and — this matters in Phase 4 — can't run truly parallel code. For that you need the full toolchain. Five names, five jobs:

Light the forge

Commands below are for Linux and macOS. Windows knights: use WSL2 and follow the Linux path. The Setup page has full per-OS instructions, package-manager alternatives and fixes for the usual ambushes — keep it open in a second tab. First, install opam and let it set up its home:

opam init takes a few minutes and offers to hook itself into your shell — say yes. Then create the course switch, wire it into the current terminal, and stock it:

opam switch create 5.5.0 downloads and compiles the compiler itself — a coffee-length wait is normal. The last line is the victory condition: if ocaml -version answers 5.5.0, the forge is lit.

Summon the starter

Download canvas-starter.zip — a minimal, complete OCaml game project: a splash of OCaml, a dune file that compiles it to JavaScript via js_of_ocaml, and a web page with a canvas. Unzip, build, serve:

Now open http://localhost:8000. A colourful square should be bouncing around a canvas — your machine just compiled OCaml to JavaScript and served it like a real web game. (opam exec -- simply runs the command inside your switch; Python's http.server is nothing OCaml-ish, just a one-line static file server.)

Time for the sacred loop: edit → build → refresh. Leave the server running in its terminal and open a second one. In the project, open the main OCaml file (src/main.ml in the starter) and find the square's colour string — change it to "hotpink", or make the speed number outrageous. Then:

Refresh the browser. Your change is live. That loop is 90% of game development; everything after this lesson just makes the edit step more interesting. Claim your XP:

The AI at the forge

You have apprentice smiths available: Claude, Antigravity and friends. Camel Quest's rule for them is simple — AI kills the grind, not the learning. Let them write what's boring and standardised: dune stanzas, js_of_ocaml FFI bindings (the repetitive glue between OCaml and browser APIs — you'll meet it properly later), HTML scaffolds. Keep for yourself what the course is actually about: game logic, types, architecture. A decent test: if getting it wrong would teach you nothing, delegate it; if getting it wrong is the lesson, write it yourself.

So a fine prompt this week is "add a dune stanza that also copies assets/ into the build output" — and a self-defeating one is "write the bounce logic for my square". Either way, read the diff before you accept it. You are the smith; they hold the tongs.

Checkpoint quiz

Loot collected

Next: back to the browser with new respect — and 120,000 pixels to paint.