Running scripts

Execute and Clear VM

  • Open a script in the Lua tab and press Execute. The editor text is executed as is, it does not need to be saved first.

  • There is one VM. Each Execute runs the code inside it: globals, listeners, receivers and signals of earlier executions stay alive and keep running. An execution that fails prints its error and leaves the VM running.

  • Clear VM calls on_unload and the unload signal, then destroys the VM: every global, listener, receiver, signal, image and packet block of every execution is gone. The next Execute starts a fresh VM.

  • require("name") looks for name.lua and name/init.lua in C:\xiaohook\lua only (a.b means a/b.lua). package.path and package.cpath are ignored and native modules cannot be loaded.

  • Scripts run in a sandbox: the only disk access is xiao.fs, limited to C:\xiaohook (see Sandbox).

Editor

  • Ctrl+C, Ctrl+X, Ctrl+V use the Windows clipboard. Without a selection, copy and cut take the whole line.
  • Ctrl+Z undo, Ctrl+Y or Ctrl+Shift+Z redo, Ctrl+A select all, Ctrl+S save, Ctrl+/ toggle comment.
  • While the editor has the focus, key presses do not reach the game.

Console

Execute opens the console window. It floats over the game while the menu is open:

  • drag its header to move it, drag its edges to resize it
  • Clear empties it, the cross closes it
  • it opens again on the next Execute

print(...) writes to the console, arguments are separated by tabs. Errors are shown in red with the file name, the line and a stack traceback.

Time limits

Phase Limit On timeout
Main chunk (top level of the executed code) 2000 ms the execution fails, the VM keeps running
One frame (packet receivers, then on_frame, the think signal and every paint listener) 100 ms the VM is cleared

Lifecycle callbacks

Global Called
on_frame(dt) every frame before the think signal and the paint listeners, dt in seconds
on_unload() when the VM is cleared (Clear VM, unload of the client), before the unload signal

on_frame is a single global: the last execution that defines it wins. An error in on_frame removes it (on_frame removed: ... in the console). An error in a paint listener, a packet receiver or a signal callback fired by the client only removes that callback.

The signals think and unload (see xiao.signal) are the preferred way to hook these events, because several executions can each add their own callback.

Order of one frame:

  1. packet receivers, for every packet captured since the last frame
  2. on_frame(dt)
  3. the think signal
  4. the paint listeners