Skip to content

Cheat sheet

The whole language on one page. Each item links to its full entry.

Types

munos
i8 i16 i32   u8 u16 u32   bool   string   image   client
T[]          // array of T

No floats. No implicit conversions — cast with i32(x) etc. Palette index 0 is transparent. → Types

Declarations

munos
var x: i32 = 10        // scalar: initializer required
var y = 5              // type inferred
const A: u32 = 0x0086  // can't rebind
var a: i32[] = [1,2,3] // array literal
var b: i32[10]         // sized array (zero-filled, starts full)

Variables · Arrays

Control flow

munos
if c { } else if d { } else { }
while c { }
for (var i = 0; i < n; i += 1) { }
break    continue    return x

Conditions must be bool. → Control flow

Functions

munos
function add(a: i32, b: i32): i32 { return a + b }
function f(x: i32, color: u32 = 0x00FFFFFF) { }   // trailing default
f(1, color = 0x00FF0000)                           // named argument

Top-level only; hoisted; not first-class. → Functions

Structs

munos
struct Player { x: i32; y: i32; name: u8[8] }
var p: Player          // zero-filled; no literal form
p.x = 100              // field access; structs are references

Structs

Client / server

munos
const SHARED = 0x0086          // visible to both roles
client { /* draw, read memory, input */ }
server { /* relay, per-player state */ }

The client {} / server {} blocks are only for multiplayer — a script with a server half. A single-player mod has no server section, so it needs no block at all: just write event frame, drawing, memory reads, and input at the top level. → Client & server

Events

munos
// client
event frame(frame_num: i32) { }
event receive(data: u8[]) { }
event input(button: i32, pressed: bool) { }
// server
event tick(tick_num: i32) { }
event receive(from: client, data: u8[]) { }
event connect(c: client, handoff: u8[]) { }
event disconnect(c: client) { }

Events

Memory · client

munos
read_u8/u16/u32(addr)   read_i8/i16/i32(addr)
write_u8/u16/u32(addr, v)   write_i8/i16/i32(addr, v)

Memory

Drawing · client

munos
image_literal(w, h, "base64")
image_from_bitmap_bytes(bytes, dx, dy)
image_from_png_bytes(bytes, x, y, w, h)   palette_from_png_bytes(bytes)
draw_image(img, pal, x, y, flip_x=false, flip_y=false,
          clip_x=0, clip_y=0, clip_w=-1, clip_h=-1,
          clip_rect_x1=-1, clip_rect_y1=-1, clip_rect_x2=-1, clip_rect_y2=-1)

Images & drawing

Networking

munos
send(data, reliable=true)              // client
send(to, data, reliable=true)          // server
pack(values, widths)    unpack(bytes, widths)
base64_decode(s)        string_from_bytes(buf, len)

Networking & packing

Input · client

munos
input_held(button)   input_pressed(button)   consume_input()
BUTTON_UP/DOWN/LEFT/RIGHT/A/B/START/SELECT

Input

ROM control · client

munos
pause_rom()   resume_rom()   local_rom_hash()   disconnect()

ROM control

Server / slots · server

munos
slot(c)   max_clients()   tick_rate()   set_tick_rate(hz)
hop(url, handoff)         redirect(c, url, handoff)

Server & slots

Instances · server

munos
spawn(label, id, handoff, persistent)   find_instance(label)
list_instances()   player_count(label)   uuid()
tell(url, data)    my_url()    instance_url(id)
shard_config()     list_shards()    list_scripts()
event receive_from(from_url, data)

Instances

Persistence · both · async

munos
db_get(ns, key, cb, ctx=0)            // cb(success, data, ctx)
db_set(ns, key, data, cb?, ctx?)      // cb(success, ctx)
db_del(ns, key, cb?, ctx?)            // cb(success, ctx)
db_list(ns, prefix, cb, ctx=0)        // cb(success, keys, ctx)
event db_error(op, ns, key, msg)

Persistence

Fetch · client · async

munos
fetch(url, cb, ctx=0)                 // cb(success, data, ctx)
event fetch_error(url, msg)

Fetch

Arrays & misc

munos
len(x)   size(x)   push(a, v)   pop(a)   copy(x)
print(...)         // variadic

Misc

Part of the MultiNostalgia project.