Vectrune documentationAlpha referenceLearning site ↗

Frontend expressions

Math, random, spatial, storage, and voxel expression helpers.

abs

abs(value)

Absolute numeric value.

Runtime: Rune-Web / game logic

Returns / effects

Number.

Example
distance = abs(delta)

Implementation: runtime/rune-web/src/expression.ts

angle_to

angle_to(a, b)

Find the direction from one point object to another.

Runtime: Rune-Web / game logic

Returns / effects

Angle in degrees normalized into [0, 360); invalid objects return 0.

Example
aim = angle_to(enemy, player)

Implementation: runtime/rune-web/src/expression.ts

atan2

atan2(dy, dx)

Compute a direction in degrees.

Runtime: Rune-Web / game logic

Returns / effects

Angle normalized into [0, 360).

Example
angle = atan2(dy, dx)

Implementation: runtime/rune-web/src/expression.ts

clamp

clamp(value, minimum, maximum)

Constrain a numeric value to bounds.

Runtime: Rune-Web / game logic

Returns / effects

Number.

Example
health = clamp(health, 0, 100)

Implementation: runtime/rune-web/src/expression.ts

collide

collide(a, b[, width=20[, height=width]])

Check axis-aligned proximity of objects with x/y coordinates.

Runtime: Rune-Web / game logic

Returns / effects

Boolean; invalid objects return false.

Example
hit = collide(player, enemy, 16, 16)

Implementation: runtime/rune-web/src/expression.ts

cos

cos(degrees)

Cosine with a degree input.

Runtime: Rune-Web / game logic

Returns / effects

Number.

Example
dx = cos(angle)

Implementation: runtime/rune-web/src/expression.ts

distance

distance(a, b) | distance(ax, ay, bx, by)

Compute Euclidean distance between points.

Runtime: Rune-Web / game logic

Returns / effects

Number.

Example
range = distance(player, enemy)

Implementation: runtime/rune-web/src/expression.ts

floor

floor(value)

Round a numeric value downward.

Runtime: Rune-Web / game logic

Returns / effects

Integer-valued number.

Example
tile = floor(player.x)

Implementation: runtime/rune-web/src/expression.ts

frontend array.any

array.any(predicate)

Test whether any element satisfies a frontend predicate.

Runtime: Rune-Web / game logic

Returns / effects

Boolean. The predicate uses it, or a named arrow parameter.

Implementation: runtime/rune-web/src/expression.ts

frontend array.filter

array.filter(predicate)

Select elements satisfying a frontend predicate.

Runtime: Rune-Web / game logic

Returns / effects

New array; supports trailing .length.

Example
alive = enemies.filter(it.alive)

Implementation: runtime/rune-web/src/expression.ts

frontend array.find

array.find(predicate)

Read the first frontend array element satisfying a predicate.

Runtime: Rune-Web / game logic

Returns / effects

Matching value, or JavaScript undefined when no element matches.

Implementation: runtime/rune-web/src/expression.ts

frontend array.mask

array.mask(value)

Build a bitmask of positions matching a value.

Runtime: Rune-Web / game logic

Returns / effects

Bitwise numeric mask; comparisons use the frontend string conversion.

Implementation: runtime/rune-web/src/expression.ts

frontend array.max

array.max(selector)

Find the maximum selected value in a frontend array.

Runtime: Rune-Web / game logic

Returns / effects

Selected value, or undefined for an empty array.

Implementation: runtime/rune-web/src/expression.ts

frontend array.push

array.push(value)

Append to an array from a frontend action.

Runtime: Rune-Web / game logic

Returns / effects

Mutates the target array.

Implementation: runtime/rune-web/src/statement.ts

Literal text binding

element rune-text=path

Display a Rune-Web value as literal, HTML-escaped text.

Runtime: Rune-Web browser and server-rendered frontend

Returns / effects

The value at the path becomes the element's inline text.

Example
pre rune-text=record.payload

Implementation: runtime/rune-web/src/rendering.ts · src/apps/rune_web/mod.rs

map_spawn

map_spawn(map_name)

Read a compiled map spawn point.

Runtime: Rune-Web / game logic

Returns / effects

Map spawn data from the current spatial configuration.

Example
spawn = map_spawn(level)

Implementation: runtime/rune-web/src/expression.ts

max

max(value, ...)

Return the maximum numeric argument.

Runtime: Rune-Web / game logic

Returns / effects

Number.

Example
high = max(a, b)

Implementation: runtime/rune-web/src/expression.ts

min

min(value, ...)

Return the minimum numeric argument.

Runtime: Rune-Web / game logic

Returns / effects

Number.

Example
low = min(a, b)

Implementation: runtime/rune-web/src/expression.ts

object and array spread

{ ...base, key: value } | [...items, extra]

Shallow-copy object properties or expand array elements inline inside literals.

Runtime: Rune-Web, Pixel, Pixel-3D, and .vect shared expression engine

Returns / effects

A new object or array containing expanded keys or elements.

Errors / edge cases

Forbidden prototype keys are rejected via safeKey.

Example
updated = { ...prim, color: active_color }
next = [...frames, new_frame]

Implementation: runtime/rune-web/src/core_expression.ts · runtime/rune-web/tests/core_features.test.ts

pick

pick(values[, seed])

Choose a value from an array.

Runtime: Rune-Web / game logic

Returns / effects

Selected value; an empty array yields null.

Example
choice = pick(options, seed)

Implementation: runtime/rune-web/src/expression.ts

Preserve an input draft

input #id data-preserve-draft=true

Keep a typed input value across unrelated Rune-Web reactivity updates.

Runtime: Rune-Web browser frontend

Returns / effects

Preserves edits when the declared value stays the same. A changed declared value replaces the draft.

Example
input #offset type=text value=latest data-preserve-draft=true

Implementation: runtime/rune-web/src/index.ts

random

random(minimum, maximum[, seed])

Generate an integer within the requested range.

Runtime: Rune-Web / game logic

Returns / effects

Random integer; an explicit seed allows repeatability.

Example
roll = random(1, 6, seed)

Implementation: runtime/rune-web/src/expression.ts

rune.format

rune.format(source, line_width?)

Conservatively format Rune source text matching `vectrune fmt --line-width` (default 100).

Runtime: Native run: builtins, Rune-Web, Pixel-3D, and .vect scripts

Parameters

source
Rune source text to format.
line_width
Target maximum line width (default 100, minimum 20).

Returns / effects

Formatted Rune source string preserving comments, key order, and opaque blocks.

Errors / edge cases

Width values below 20 are clamped to 20.

Example
pretty = rune.format(raw_rune, 100)

Implementation: src/builtins.rs · src/cli/formatting.rs · runtime/rune-web/src/rune_fmt.ts · runtime/rune-web/tests/rune_fmt.test.ts

rune.parse

rune.parse(source)

Parse Rune source text into structured sections `{ sections: [{ kind, name, path, kv, series }] }`.

Runtime: Native run: builtins, Rune-Web, Pixel-3D, and .vect scripts

Parameters

source
Rune document source text to parse.

Returns / effects

Object with a `sections` array of `{ kind, name, path, kv, series }` entries.

Errors / edge cases

Malformed Rune input returns an error in native run: or best-effort sections in web/Vect.

Example
doc = rune.parse(source)
for sec in doc.sections:
    if sec.kind == "Model":
        models.push(sec.name)

Implementation: src/builtins.rs · runtime/rune-web/src/rune_parse.ts · runtime/rune-web/src/core_expression.ts · examples/rune-web/model_studio/parts/logic/codec.rune

sees

sees(a, b) | sees(x1, y1, x2, y2)

Check line of sight through the active map.

Runtime: Rune-Web / game logic

Returns / effects

Boolean.

Example
visible = sees(enemy, player)

Implementation: runtime/rune-web/src/expression.ts

shuffle

shuffle(values[, seed])

Return a seeded shuffled copy of an array.

Runtime: Rune-Web / game logic

Returns / effects

Array; input is not shuffled in place.

Example
deck = shuffle(cards, seed)

Implementation: runtime/rune-web/src/expression.ts

sin

sin(degrees)

Sine with a degree input.

Runtime: Rune-Web / game logic

Returns / effects

Number.

Example
dy = sin(angle)

Implementation: runtime/rune-web/src/expression.ts

slide

slide(x, y, dx, dy[, radius=0.25])

Move a circle through the active grid collision space with sliding.

Runtime: Rune-Web / game logic

Returns / effects

Position object returned by the spatial runtime.

Example
position = slide(player.x, player.y, dx, dy)

Implementation: runtime/rune-web/src/expression.ts

sqrt

sqrt(value)

Compute the square root.

Runtime: Rune-Web / game logic

Returns / effects

Number; negative input follows JavaScript NaN behavior.

Example
root = sqrt(9)

Implementation: runtime/rune-web/src/expression.ts

url_encode

url_encode(value)

Encode one string as a URL component in Rune-Web.

Runtime: Rune-Web / game logic

Returns / effects

The percent-encoded component string.

Example
query_url = base_url + url_encode(place)

Implementation: runtime/rune-web/src/expression.ts

voxel_fill

voxel_fill(world, from, size, block)

Fill or carve a rectangular block region.

Runtime: Rune-Web / game logic

Returns / effects

Mutated world object.

Implementation: runtime/rune-web/src/pixel3d/voxel.ts

voxel_generate

voxel_generate(seed[, biome="meadow"])

Generate a seeded block world.

Runtime: Rune-Web / game logic

Returns / effects

Voxel world state object.

Implementation: runtime/rune-web/src/pixel3d/voxel.ts

voxel_get

voxel_get(world, x, y, z)

Read block occupancy at integer coordinates.

Runtime: Rune-Web / game logic

Returns / effects

Block identifier.

Implementation: runtime/rune-web/src/pixel3d/voxel.ts

voxel_mine

voxel_mine(world, player)

Mine the block targeted by a player.

Runtime: Rune-Web / game logic

Returns / effects

Object with block and hit; mutates world occupancy.

Implementation: runtime/rune-web/src/pixel3d/voxel.ts

voxel_move

voxel_move(world, player, dx, dy[, jump=false[, options]])

Advance movement with voxel collision, gravity, jumping, and elevation.

Runtime: Rune-Web / game logic

Returns / effects

Updated player state.

Implementation: runtime/rune-web/src/pixel3d/voxel.ts

voxel_target

voxel_target(world, player)

Trace the block targeted by a player camera.

Runtime: Rune-Web / game logic

Returns / effects

Voxel hit object, or null.

Implementation: runtime/rune-web/src/pixel3d/voxel.ts