Scripting in Go

A map's rules are a Go program. It is ordinary Go, and you write it in the code editor you already use. W4 builds it to WebAssembly and the game runs it beside the simulation, in a sandbox. There is no W4 language to learn. GUI triggers are planned for later, as a layer that writes Go for you.

New here? Do Your first script first, then come back.

The shape of a script

A script is a main function that says what should happen when. The game runs main once, before the map starts, so main only registers things. The work happens in the functions you hand over.

package main

import (
	"w4/event"
	"w4/game"
)

func main() {
	event.OnMapInit(func() {
		game.Print("hello from the map")
	})
}

Four packages make up the API:

fmt.Println works too. Whatever the script writes to standard output ends up in the same log window as game.Print.

The full list of functions and types is the Scripting API reference. It is generated from the SDK's own doc comments. The pages here explain how the pieces fit together.

In this section

In this section