Build a WebAssembly text (WAT) robot

Write a robot in WebAssembly text for Clunkyard's Reflex class. The WAT starter includes the robot SDK's imports and record offsets at build time. You write the module and control its memory directly.

Build, try and debug

WAT starter

In the workbench, create a WAT robot and edit bot.wat. Save, wait for the build and queue hosted practice.

See the local player kit for your platform and toolchain setup.

npx @clunkyard/cli new wat my-robot
cd my-robot
npx @clunkyard/cli doctor
npx @clunkyard/cli build
npx @clunkyard/cli match
npx @clunkyard/cli replay

Define the module

Put the SDK include inside module before your own definitions. Export one memory and the two functions the match host calls. Each function returns zero to continue the match.

(module
  ;; @include clunkyard
  (memory (export "memory") 1)
  (func (export "clunkyard_start") (result i32)
    i32.const 0)
  (func (export "clunkyard_turn") (result i32)
    (drop (call $cy_drive_throttle (f64.const 0.5)))
    (drop (call $cy_drive_turn (f64.const 0.33)))
    i32.const 0))

The starter build expands the include before assembling the module. If wat2wasm reports an undefined $cy_ function, use the starter build so the SDK can supply it. To read a contact, reserve space in memory, call the import and check $CY_OK before loading the record. See the ABI 4 reference for function signatures and the turn trace for runtime errors.

Download this page as Markdown