ScriptingScheduling and keys¶
Timers¶
var handle = schedule(function () { /* … */ }, 500); // milliseconds
var handle = scheduleTicks(function () { /* … */ }, 20); // client ticks
cancel(handle);
Callbacks run on the client thread, on the tick, so the resolution is 50 ms and a 10 ms delay behaves like a 50 ms one. Everything a script schedules is cancelled when it reloads.
Keys¶
keybinds.isDown(code) // true every tick the key is held
keybinds.isPressed(code) // true exactly once, when it goes down
keybinds.isMouseDown(0) // 0 left, 1 right, 2 middle
keybinds.code('RSHIFT') // LWJGL code, 0 when unknown
keybinds.name(code)
Use isPressed for anything that toggles
A script polling isDown and toggling fires twenty toggles per press, which reads as "the bind does nothing" because it lands back where it started.
util¶
util.time() // ms since the epoch
util.nanos()
util.strip(s) // remove § codes
util.colour(s) / util.color(s) // &a → §a
util.argb(r, g, b, a) util.rgb(r, g, b) util.hex(argb)
util.accent() // the live theme accent
util.distance(x1,y1,z1, x2,y2,z2) util.distance2d(x1,z1, x2,z2)
util.round(v, dp) util.format(v, dp) util.clamp(v, lo, hi) util.random(lo, hi)
require¶
The library file is evaluated with its own module/exports pair. Each script gets its own copy: a library holding state is not shared between scripts that know nothing about each other. Files in lib/ are never auto-loaded as scripts; that is the whole reason the folder exists. The name is a file name, not a path: require('../x') is refused.