PLUG'N SCRIPT
rapid plugin development
Tutorial
DSP
KUIML
How-to
Scripts
  • Overview
  • Tutorial
  • Reference
Layout and positioning
  • CELL
  • TABLE
Language basics
  • SKIN
  • DUMMY
  • INCLUDE
  • INCLUDE_ONCE
  • DEFINE
  • UNDEFINE
  • VARIABLE
  • LOCAL_VARIABLE
  • TEMPLATE
  • TEMPLATE_INNER_CONTENT
  • TEMPLATE_UNLOAD
  • REPEAT
Text widgets
  • TEXT
  • TEXT_FIELD
  • TEXT_EDIT_BOX
  • TOOLTIP
  • PARAM_TEXT
  • PARAM_TEXT_CONTROL
  • PARAM_TEXT_EDIT_BOX
  • PARAM_TOOLTIP
Image widgets
  • IMAGE
  • IMAGE_ACTION_BUTTON
  • IMAGE_GROUP_BOX
  • IMAGE_PARAM_BUTTON
  • IMAGE_PARAM_KNOB
  • IMAGE_PARAM_LINEAR_METER
  • IMAGE_PARAM_MENU_BUTTON
  • IMAGE_PARAM_METER
  • IMAGE_PARAM_SLIDER
  • IMAGE_PARAM_TOGGLE_SWITCH
  • XYZ_IMAGE_PARAM_JOYSTICK
Invisible controls
  • INVISIBLE_ACTION_BUTTON
  • INVISIBLE_PARAM_BUTTON
  • INVISIBLE_PARAM_KNOB
  • INVISIBLE_PARAM_MENU_BUTTON
  • INVISIBLE_PARAM_SLIDER
  • INVISIBLE_PARAM_TOGGLE_SWITCH
  • XY_PARAM_PAD
  • XY_ZOOM_SELECT_PAD
  • XYZ_PARAM_SCRATCH_PAD
  • XYZ_PARAM_CLICK_PAD
Drawing, curves & 3D
  • CANVAS
    • Graphics API
  • svg
  • CURVE_GRAPH
  • XY_CURVES_GRAPH
  • GRID
  • RULER
  • COLOR_SCALE
  • VIEW_3D
  • COLOR_SURFACE_3D
  • GRID_3D
  • GL_OBJECT_3D
    • OpenGL Cheat Sheet
  • SURFACE_COLORMAP_2DPLOT
Miscellaneous
  • SCRIPT
  • WIDGET
  • KUIML_WIDGET
  • POPUP_MENU
  • MENU_ITEM
  • MENU_SEPARATOR
  • FILE_SELECT_MENU
  • SYSTEM_ACTION_BUTTON
  • SYSTEM_PARAM_CHECKBOX
  • SYSTEM_PARAM_DROPDOWN_LIST
  • WINDOW
  • LOAD_FONT
Data model
  • STRING
  • PARAM
  • FORMULA_PARAM
  • PARAM_ANIMATOR
  • ACTION
    • Built-in action types
  • TIMER
  • ACTION_TRIGGER
  • CURVE
  • FORMULA_CURVE
  • CURVE_FROM_PARAM_OVER_TIME
  • SURFACE
  • FORMULA_SURFACE
  • SURFACE_FROM_CURVE_OVER_TIME
  • GROUP
Links and commands
  • PARAM_LINK
  • PARAM_MULTI_LINK
  • PARAM_CONNECTION
  • PARAM_TO_STRING_LINK
  • STRING_LINK
  • STRING_MULTI_LINK
  • CURVE_LINK
  • CURVE_MULTI_LINK
  • SURFACE_LINK
  • REQUIRED_OBJECTS
  • EXPOSED_OBJECTS
  • PERSISTENT_OBJECTS
Common attrubutes
  • For all elements
  • Widgets
  • Param Widgets
  • Param Controls
  • Param Info Viewers
  • Text Widgets
  • Surface Viewers
  • Curve Viewers
  • Images
  • 3D Objects
Additional information
  • All attributes
  • Attribute types
  • Cursors
  • Math formulas
  • Scripting
    • Built-in addons
  • User experience
  • Errors and solutions
  • Built-in variables
  • Runtime model
  • Parameters mapping
  • Script converter
  • LetiMix
KUIMLReferenceScripting
August 23, 2025

Scripting

Engine

KUIML uses AngelScript for its scripting engine, with the following add-ons:

  • Math functions (using double precision instead of float), with the addition of the exp() function
  • Script Arrays
  • Strings (string functions)
  • File
  • Dictionary
  • Filesystem
  • Datetime
  • Custom addons (XML parsing, utf-8 iterator, graphics, StopWatch, etc).

Also, strings use double quotes only. Simple quotes are reserved for a single character, like in C or C++.

Related KUIML Elements

Separate script files can be loaded in KUIML using the SCRIPT element.

Separate build-time scripts/functions can be loaded via SKIN build_time_script_include attribute to provide additional functionality for VARIABLE built-time scripting.

Scripts can also be written directly (inline) as attributes of the SCRIPT, ACTION_TRIGGER or ACTION (Script type), GL_OBJECT_3D, CANVAS and VARIABLE elements. Some characters (like &, ", <) need to be escaped in Inline scripts. See our online script converter.

Data model (PARAMs, STRINGS, ACTIONS, etc) can be exposed to scripts using the EXPOSED_OBJECTS element, and also via requires and exposed attributes in particular elements.

How it works

Once the structure of the user interface and data model have been described using KUIML elements and connected together with links (see build-time/runtime), it is possible to write scripts that perform more complex actions on the data model on behalf of the end-user. Most of the elements and their attributes are available to the scripting engine (see the "E (exposed)" column in the attributes list in the elements reference).

  1. <!-- create a param and a string -->
  2. <PARAM id="demo_param" min="0" max="20" default="10" />
  3. <STRING id="demo_string" default="Hello, World!" />

  4. <!-- display string and param values -->
  5. <TEXT string_id="demo_string" width="100" />
  6. <PARAM_TEXT param_id="demo_param" />

  7. <!-- a widget to draw a line -->
  8. <WIDGET id="widget_line" width="100" height="3" background_color="#DD0000" />

  9. <!-- a simple button to run an action -->
  10. <SYSTEM_ACTION_BUTTON action_id="run_my_script" width="100" />

  11. <!-- demo action to change color of the line -->
  12. <ACTION id="change_color" type="Script" script=" 
  13. widget_line.background_color.r = rand(0,1);
  14. widget_line.background_color.g = rand(0,1);
  15. widget_line.background_color.b = rand(0,1);
  16.  " requires="widget_line.background_color.*" />

  17. <!-- demo action to run when button is clicked -->
  18. <ACTION id="run_my_script" type="Script" script=" 
  19. /* update STRING - looks like a simple string, actually is a Kt::String */
  20. demo_string = &quot;Param was: &quot; + demo_param;

  21. /* update PARAM - looks like a simple variable, actually is a Kt::Param */
  22. demo_param++;

  23. /* run an ACTION - looks like a simple function, actually is a Kt::Action */
  24. change_color();
  25.  " name="Run script" requires="demo_string;demo_param;change_color" />

You can see in the code, that accessing PARAM or STRING or ACTION from the script is easy and looks identical to accessing a regular variable (double, string) or a function calls. However, they are represented as a different types of objects. It can be important to understand if you want to pass them as an argument to a function, or run some specific operations, that are possible only with real strings or doubles (or with actual kuiml objects).

KUIML model elements like PARAM, STRING, ACTION, CURVE, SURFACE and events are made available to the scripting engine using the following classes (they are all reference types):

  • Kt::Param : behaves like a double, supporting most common operators (++,–,+=,-=,*=,/= etc.)
    There's also a parent Kt::ConstParam for read-only params.
  • Kt::String : behaves like a native string, implements basic operations, such as concatenation (+=)
    There's also a parent Kt::ConstString for read-only strings.
  • Kt::Curve : acts as a unary function double f(double x). double v=curve(10.0); Can be copied with =
    There's also a parent Kt::ConstCurve for read-only curves.
  • Kt::Surface : acts as a binary function double f(double x,double y); double v=surface(10.0, 20.0); Can be copied with =. There's also a parent Kt::ConstSurface for read-only surfaces.
  • Kt::Action : simple function f(); Can be called via f()
  • Kt::Event : supports += and -= operators to register callback functions.
  • Kt::Object is just a base class for all the objects (listed above) in the scripting engine. Inherited by Kt::Action, Kt::ConstCurve, Kt::ConstParam, Kt::ConstString, Kt::ConstSurface, and Kt::Event.

Here's an example on how it can be useful to understand. We make two identical functions, call them seemingly identically, the only difference is the type of argument they receive.

  1. <!-- create a param -->
  2. <PARAM id="demo_param" min="0" max="20" default="10" />

  3. <!-- display param value -->
  4. <PARAM_TEXT param_id="demo_param" />

  5. <!-- two demo functions -->
  6. <SCRIPT script=" 
  7. void updateParam(double param) {
  8. param++;
  9. }
  10. void trulyUpdateParam(Kt::Param@ param) {
  11. param++;
  12. }
  13.  " />

  14. <!-- demo action to run when button is clicked -->
  15. <ACTION id="run_my_script" type="Script" script=" 
  16. updateParam(demo_param); /* this doesn't really update param */
  17. trulyUpdateParam(demo_param); /* this works as expected */
  18.  " name="Run script" requires="demo_param" />

  19. <!-- a simple button to run an action -->
  20. <SYSTEM_ACTION_BUTTON action_id="run_my_script" width="100" />

Another example how to create an empty "placeholder" reference in the script (Kt::Param@), and then attach it to real parameters.

  1. <!-- create a param -->
  2. <PARAM id="demo_param1" min="0" max="20" default="10" />
  3. <PARAM id="demo_param2" min="0" max="20" default="10" />

  4. <!-- display param value -->
  5. <PARAM_TEXT param_id="demo_param1" />
  6. <PARAM_TEXT param_id="demo_param2" />

  7. <!-- demo action to run when button is clicked -->
  8. <ACTION id="run_my_script" type="Script" script=" 
  9. Kt::Param@ param;
  10. @param = demo_param1; /* reference first param */
  11. param++;
  12. @param = demo_param2; /* reference second param */
  13. param++;
  14.  " name="Run script" requires="demo_param1;demo_param2" />

  15. <!-- a simple button to run an action -->
  16. <SYSTEM_ACTION_BUTTON action_id="run_my_script" width="100" />

Access params as array

Though KUIML doesn't support arrays, we can use script arrays and use a nice trick to link script array to actual params.

  1. <!-- how much params in array we need -->
  2. <VARIABLE id="ARRAY_SIZE" value="10" />

  3. <!-- create a placeholder script array of references to params -->
  4. <SCRIPT script=" 
  5. array&lt;Kt::Param@> my_params($ARRAY_SIZE$);
  6.  " />

  7. <!-- repeat several times, updating $index$ variable -->
  8. <REPEAT count="$ARRAY_SIZE$">
  9. <!-- create a param -->
  10. <PARAM id="demo_param$index$" min="0" max="40" default="10" />
  11. <!-- link each param to an script array of Kt::Param@ -->
  12. <ACTION_TRIGGER event_id="window.loaded.value_changed" condition_formula="window.loaded==1" script="@my_params[$index$] = demo_param$index$;" requires="demo_param$index$" />
  13. </REPEAT>

  14. <!-- display param values -->
  15. <ROW spacing="1" height="60">
  16. <REPEAT count="$ARRAY_SIZE$" height="50">
  17. <COLUMN width="25" v_align="bottom">
  18. <!-- draw a vertical line -->
  19. <WIDGET id="w_column_$index$" width="20" height="30" background_color="#FF99CC" />
  20. <!-- display text value -->
  21. <PARAM_TEXT param_id="demo_param$index$" font_size="10" />
  22. </COLUMN>
  23. <!-- link param value to widget height and color -->
  24. <PARAM_LINK from="demo_param$index$" to="w_column_$index$.height" />
  25. <PARAM_LINK from="demo_param$index$" to="w_column_$index$.background_color.r" formula="x/40" />
  26. </REPEAT>
  27. </ROW>

  28. <!-- access params as items in an array -->
  29. <ACTION id="run_my_script" type="Script" script=" 
  30. for(uint i=0; i &lt; my_params.length; i++) {
  31. my_params[i] = rand(0,40);
  32. }
  33.  " name="Run script" />

  34. <!-- a simple button to run an action -->
  35. <SYSTEM_ACTION_BUTTON action_id="run_my_script" width="100" />

Search in a string

To do some string-related operations you usually need to convert Kt::String to a regular string.

  1. <!-- create a kuiml string -->
  2. <STRING id="my_string" default="Hello!" />

  3. <!-- trying to search in a string when it changes -->
  4. <ACTION_TRIGGER event_id="my_string.value_changed" script=" 
  5. /* first we convert Kt::String to a regular string */
  6. string s = my_string;
  7. /* now we can search in its contents */
  8. if (s.findFirst(&quot;World&quot;)>-1) {
  9. my_string = &quot;Welcome!&quot;;
  10. }
  11.  " name="Run script" requires="my_string" />

  12. <!-- display and edit a string -->
  13. <TEXT_FIELD string_id="my_string" width="100" />

Creating shorthands using auto

In this example we show how to create references to random KUIML object (using "auto" class), how to reference to a PARAM and a STRING, how to change a reference on the fly.

  1. <!-- widget for the demo -->
  2. <WIDGET id="my_widget" width="40" height="40" background_color="#000000" mouse_sensitive="true" />

  3. <!-- add global script variables -->
  4. <SCRIPT script=" 
  5. array&lt;double> phase = {0, 0.4, 0.8, 1};
  6.  " />

  7. <!-- a timer and an action -->
  8. <TIMER id="forever_timer" refresh_time_ms="20" />
  9. <ACTION_TRIGGER event_id="forever_timer.elapsed"
  10. script=" 

  11. /* create an alias/reference to background_color (unknown type object) */
  12. auto bg = my_widget.background_color;

  13. /* update widget's background_color */
  14. bg.r = cos(phase[0])/2 + 0.5;
  15. bg.g = cos(phase[1])/2 + 0.5;
  16. bg.b = cos(phase[2])/2 + 0.5;

  17. /* create a reference to widget itself */
  18. auto w = my_widget;
  19. w.width = w.height + w.height * (cos(phase[3])+1)*grow_param;

  20. /* create a reference to a PARAM (just because we can) */
  21. Kt::Param@ sp = speed_param;

  22. /* update phase for each color */
  23. phase[0] += 0.04*sp; /* acts as a double, though is Kt::Param@) */
  24. phase[1] += 0.08*sp;
  25. phase[2] += 0.02*speed_param; /* we can use PARAM directly */
  26. phase[3] += 0.1*speed_param;

  27. /* format hex value to a string */
  28. string hex = formatUInt(uint(bg.r*255), &quot;0H&quot;, 2);
  29. hex += formatUInt(uint(bg.g*255), &quot;0H&quot;, 2);
  30. hex += formatUInt(uint(bg.b*255), &quot;0H&quot;, 2);

  31. /* let's create a reference to a STRING */
  32. Kt::String@ str = output_string;

  33. /* add some randomness just for fun */
  34. if (rand(0,100)>95) {
  35. /* change reference to another STRING */
  36. @str = output_string2;
  37. }

  38. /* update STRING contents */
  39. str = &quot;color: #&quot; + hex;

  40.  " requires="my_widget.background_color.*;my_widget.height;my_widget.width;grow_param;speed_param;output_string;output_string2" />

  41. <!-- param and control -->
  42. <PARAM id="speed_param" min="0" max="4" default="1" />
  43. <PARAM id="grow_param" min="0" max="3" default="0.4" />
  44. <ROW spacing="10">
  45. <PARAM_TEXT_CONTROL param_id="speed_param" content="Speed: {value}" pixel_range="400" value_format="0.2" />
  46. <PARAM_TEXT_CONTROL param_id="grow_param" content="Grow: {value}" pixel_range="400" value_format="0.2" />
  47. </ROW>

  48. <!-- string and output -->
  49. <STRING id="output_string" default="" />
  50. <TEXT_FIELD string_id="output_string" width="300" font_size="12" />
  51. <STRING id="output_string2" default="" />
  52. <TEXT_FIELD string_id="output_string2" font_size="12" />

Binding functions to events

In scripts you can access Kt::Event objects and bind or unbind script functions to it (in KUIML you can do similar things with ACTION_TRIGGER). Here's a simple demo.

  1. <!-- create a param -->
  2. <PARAM id="demo_param" min="0" max="100000" default="10" />

  3. <!-- display param value -->
  4. <PARAM_TEXT param_id="demo_param" />

  5. <!-- draw a demo line -->
  6. <WIDGET id="demo_widget" background_color="#0000DD" width="20" height="5" />

  7. <!-- a timer and an action -->
  8. <TIMER id="forever_timer" refresh_time_ms="200" />
  9. <ACTION_TRIGGER event_id="forever_timer.elapsed"
  10. script=" demo_param+=rand(-20,20); " requires="demo_param" />

  11. <!-- several script functions -->
  12. <SCRIPT script=" 
  13. /* a function to change the width of the widget */
  14. void updateWidget(){
  15. demo_widget.width = demo_param;
  16. }

  17. /* bind a script function to an event */
  18. void bind(){
  19. demo_param.value_changed += updateWidget;
  20. }

  21. /* unbind a script function from an event */
  22. void unbind(){
  23. demo_param.value_changed -= updateWidget;
  24. }
  25.  " requires="demo_param.value_changed;demo_widget.width" />

  26. <!-- demo actions to run when button is clicked -->
  27. <ACTION id="do_bind" type="Script" script="bind();" name="Bind" />
  28. <ACTION id="do_unbind" type="Script" script="unbind();" name="Unbind" />

  29. <!-- a simple buttons to run actions -->
  30. <SYSTEM_ACTION_BUTTON action_id="do_bind" width="100" />
  31. <SYSTEM_ACTION_BUTTON action_id="do_unbind" width="100" />

Accessing param default values

Sometimes you may need to access PARAM "default" attribute from script. In AngelScript "default" is a reserved word, so use "defaultValue" instead.

  1. <!-- create a param -->
  2. <PARAM id="demo_param" min="0" max="20" default="10" />

  3. <!-- display param defaultvalue -->
  4. <PARAM_TEXT_CONTROL param_id="demo_param.default" />

  5. <!-- demo action to run when button is clicked -->
  6. <ACTION id="run_my_script" type="Script" script=" 
  7. /* this will not work, cause 'default' is a reserved word in AngelScript */
  8. /* demo_param.default = rand(0,20); */

  9. /* instead of .default use .defaultValue */
  10. demo_param.defaultValue = rand(0,20);

  11.  " name="Run script" requires="demo_param.default" />

  12. <!-- a simple button to run an action -->
  13. <SYSTEM_ACTION_BUTTON action_id="run_my_script" width="100" />

Objects Exposure

For performance reasons, the KUIML engine does not create script objects for all elements that could be exposed by the data model.

So it is necessary to explicitely describe the objects that will be used by scripts so that they are properly exposed. See the "requires" attribute of the SCRIPT and EXPOSED_OBJECTS element.

You can of course expose all objects using the '*' wildcard to start writing the scripts, but exposed elements should definitely be filtered before releasing, or customers may encounter performance issues, especially with complex user interfaces with multiple elements.


Comments

Please, authorize to view and post comments.

2020 - 2025 © Site by LetiMix · Donate  |  Plug'n Script and KUIML by Blue Cat Audio