Where the API lives

The w4 module ships with the editor. It is not copied into every map. The editor writes it once per computer into your data folder:

System Folder
Windows %LOCALAPPDATA%\W4\go-sdk\<version>\w4
macOS ~/Library/Application Support/W4/go-sdk/<version>/w4
Linux ~/.local/share/w4/go-sdk/<version>/w4

AQUA4_GO_SDK_DIR overrides the folder.

What the map holds

The map's scripts/ folder has three kinds of file:

  • go.mod, which says require w4 v0.1.0.
  • go.work, which points at the folder above. It is specific to your computer. The editor rewrites it before every build and every open, and writes a .gitignore so it stays out of git.
  • Your own .go files.

Because the API is not inside the map, a map stays small, and every map on a computer uses the same API. A map made before this change loses its old scripts/w4/ copy the first time the Triggers module opens it.

gopls

gopls is Go's language server. Your code editor uses it for completion, hover text and errors as you type. The Script compiler card in the Triggers module shows whether it is on (Code hints in your editor). Turn on runs go install golang.org/x/tools/gopls@latest for you. Open the scripts/ folder as the project, which Open in editor does, and gopls reads go.work and finds w4/event, w4/game and w4/ui.

Building by hand

GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o map.wasm .

Run it in the scripts folder if you prefer a terminal. The editor notices the changed map.wasm. More on Build, play and errors.

Packages

Three packages are for you: event, game and ui. A fourth, internal/host, holds the raw calls into the engine. Go does not let a map import it, and you never need to.