Skip to content

Lua: Set a Controller's Value with set_value


In Lua context, the value of a controller can be set with set_value function.

Lua Syntax

-- setting the value at once:
local myCtrlMulti = create_controller{kind="dynamic",dimension=4,name="CtrlMulti"}
set_value{ctrl=myCtrlMulti, value={0.7,-2,3.1,-4.9}}
-- or (no brackets):
set_value(myCtrlMulti, {0.7,-2,3.1,-4.9})

-- for setting the value of a particular rank:
set_value{ctrl=myCtrlMulti, value=3.1, rank=2}  -- ⚠️ the rank is zero-based, so '2' means 3rd rank!

-- for creating a smooth transition from the current to the new value:
set_value{ctrl=myCtrlMulti, value={0.7,-2,3.1,-4.9}, time=0.5}
-- (the rank parameter can also be used here.)


The set_value function requires the following arguments (2 to 4):

  • controller: the controller whose value we want to set. This can be either a reference (myCtrlMulti, i.e. a pointer) or a string ("CtrlMulti").
  • value: either a number (if dimension=1 or if rank is specified) or a table (=an array) of values.
  • rank (optional): if the rank is passed (zero-based!), the value (a number) is set to the specified rank of the multimensional controller.
  • time (optional): use the time (in seconds) parameter for a smooth transition from the current to the new value. This is equivalent to the set-message lisp function.

★     ★