Lua API
Complete reference for the VParamix Generic Script Lua interface.
This page documents every callable in the current Generic Script Lua surface. vparamix.params.declare() is setup-only. finite(), number(), error(), and the math library work during setup or update. The remaining runtime callables are available only inside the global update() function.
Program contract
local params = vparamix.params
local output = params.declare({
{ name = "Pulse", min = 0, max = 1, default = 0 },
})
function update()
output.set("Pulse", params.get("TimeSeconds") % 2)
endSetup must call vparamix.params.declare() exactly once and define a global update(). Setup and update() return nothing.
update
update()VParamix calls this global function once per Script frame after setup succeeds. It must set every declared output and return nothing.
vparamix.params.declare
vparamix.params.declare(definitions: VParamixParameterDefinition[]) -> VParamixOutputWriterDeclares the program's complete output set during setup and returns an output writer. definitions must be a dense array of 1–256 tables.
| Field | Type | Default | Rules |
|---|---|---|---|
name | string | required | Non-empty ASCII letters, digits, and underscores; unique in the program. |
min | number | -1 | Finite and lower than max. |
max | number | 1 | Finite and higher than min. |
default | number | 0 | Finite and inside min..max. |
An output name cannot collide with a predefined source or an earlier program's output. Catalog order decides ownership when two programs declare the same name.
output.set
output.set(name: string, value: number)Sets a finite numeric value for a declared output. It returns nothing. Every declared output must be set during each successful update(). Repeated writes use the last value, and successful values are clamped to the declaration range. Unknown names, nonnumeric values, nonfinite values, or missing outputs fail the entire update.
Input values
vparamix.params.get
vparamix.params.get(name: string) -> numberReturns the current regular source value, VTube Studio state value, or previous successful output of a Script program. A known but unavailable source returns its declared default.
vparamix.params.get_previous
vparamix.params.get_previous(name: string) -> numberReturns the value this program observed for the same input during its previous successful update. Before the first successful observation, it returns the input's known default.
vparamix.face.get
vparamix.face.get(name: string) -> numberReturns a current approved raw face-tracking value, including supported blendshapes, FaceFound, head rotation and position, and eye rotation.
vparamix.face.get_previous
vparamix.face.get_previous(name: string) -> numberReturns the raw face value this program observed during its previous successful update, or the known default before one exists.
All four getters require an exact parameter name. An unknown name fails the update. Reading a face parameter through vparamix.params, or a regular parameter through vparamix.face, reports the correct namespace and fails the update.
Timing
dt
dt() -> numberReturns seconds since this program's previous successful update, or 0 initially. Failed updates do not advance it.
time
time() -> numberReturns seconds since this program's runtime clock started, or 0 in stateless evaluation.
vts_ups
vts_ups() -> numberReturns the configured VTube Studio updates per second, not measured network throughput.
Conversion and validation
finite
finite(value: number) -> booleanReturns false for NaN and positive or negative infinity; otherwise returns true.
number
number(value: any) -> numberConverts a number unchanged, true to 1, false to 0, and a numeric string to its number. Other values and invalid numeric strings return 0.
error
error(message: string)Stops evaluation with message. During update(), all staged outputs, state, and VTS actions are discarded.
Saved state
save
save(id: string, value: number) -> numberStores a numeric value under a program-private string ID and returns value. The value is retained only when the update succeeds. Each program retains at most 256 IDs. Once full, writes to existing IDs still work, while a new ID is not retained.
load
load(id: string, default: number) -> numberReturns the value saved earlier in the current update, then the value retained from the previous successful update, or default when the ID does not exist.
function update()
local count = load("count", 0)
if keyboard.pressed("Space") then
count = save("count", count + 1)
end
output.set("Count", count)
endRandom values
Random helpers are available during update(); math.random and math.randomseed are not available.
rand
rand() -> numberReturns a uniform value in [0, 1).
rand_float
rand_float() -> number
rand_float(max: number) -> number
rand_float(min: number, max: number) -> numberWith no arguments, returns a uniform value in [0, 1). One argument returns rand() * max; negative bounds are allowed. Two arguments return min + rand() * (max - min).
rand_bool
rand_bool(probability?: number) -> booleanReturns true with the supplied probability. The default is 0.5, and the probability is clamped to 0..1.
Keyboard
Keyboard functions use canonical key IDs such as Space, KeyQ, ControlLeft, and UpArrow. Use -- @inspect source=keyboard to choose a valid ID in the editor. Unknown IDs and empty combinations return false.
keyboard.down
keyboard.down(key_id: string) -> booleanReturns whether the key, or every key encoded by that canonical ID, is currently down.
keyboard.pressed
keyboard.pressed(key_id: string) -> booleanReturns whether all mapped keys are down and at least one was up during the previous successful update.
keyboard.released
keyboard.released(key_id: string) -> booleanReturns whether all mapped keys were down previously and at least one is now up.
keyboard.combo
keyboard.combo(keys: string[]) -> booleanReturns whether every key ID in the dense string array is down.
keyboard.combo_pressed
keyboard.combo_pressed(keys: string[]) -> booleanReturns whether the complete combination has just become down.
keyboard.shortcut_pressed
keyboard.shortcut_pressed(action_key: string, modifiers: string[]) -> booleanReturns whether the action key transitioned down while every modifier is down.
local shortcut = keyboard.shortcut_pressed("KeyQ", { "ControlLeft", "ShiftLeft" })Math
VParamix exposes Lua 5.4's math library except math.random and math.randomseed. Use rand(), rand_float(), or rand_bool() for random values. Angles are in radians unless a function says otherwise.
math.abs
math.abs(x: number) -> numberReturns the absolute value of x. The result keeps the integer or float subtype of the argument.
math.acos
math.acos(x: number) -> numberReturns the arc cosine of x in radians.
math.asin
math.asin(x: number) -> numberReturns the arc sine of x in radians.
math.atan
math.atan(y: number, x?: number) -> numberReturns the arc tangent of y / x in radians, using both signs to select the correct quadrant. x defaults to 1.
math.ceil
math.ceil(x: number) -> numberReturns the smallest integral value greater than or equal to x. The result is an integer when it fits the integer range, or a float otherwise.
math.cos
math.cos(x: number) -> numberReturns the cosine of x radians.
math.deg
math.deg(x: number) -> numberConverts x from radians to degrees.
math.exp
math.exp(x: number) -> numberReturns e raised to the power x.
math.floor
math.floor(x: number) -> numberReturns the largest integral value less than or equal to x. The result is an integer when it fits the integer range, or a float otherwise.
math.fmod
math.fmod(x: number, y: number) -> numberReturns the remainder of x / y when the quotient is rounded toward zero. The result follows Lua's integer-or-float rules.
math.log
math.log(x: number, base?: number) -> numberReturns the logarithm of x. Without base, it returns the natural logarithm.
math.max
math.max(x: number, ...: number) -> numberReturns the greatest supplied value. At least one argument is required.
math.min
math.min(x: number, ...: number) -> numberReturns the least supplied value. At least one argument is required.
math.modf
math.modf(x: number) -> number, numberReturns the integral part of x, followed by its fractional part. The fractional result is always a float.
math.rad
math.rad(x: number) -> numberConverts x from degrees to radians.
math.sin
math.sin(x: number) -> numberReturns the sine of x radians.
math.sqrt
math.sqrt(x: number) -> numberReturns the square root of x.
math.tan
math.tan(x: number) -> numberReturns the tangent of x radians.
math.tointeger
math.tointeger(x: any) -> integer | nilReturns x as an integer when it has an exact integer representation; otherwise returns nil.
math.type
math.type(x: any) -> "integer" | "float" | nilReturns the numeric subtype of x, or nil when x is not a number.
math.ult
math.ult(m: integer, n: integer) -> booleanReturns whether m is less than n when both integers are compared as unsigned values.
Math constants
| Name | Type | Meaning |
|---|---|---|
math.huge | number | A positive float greater than every finite numeric value. |
math.maxinteger | integer | The greatest representable Lua integer. |
math.mininteger | integer | The least representable Lua integer. |
math.pi | number | The value of pi. |
Last updated on