Scripting functions
While creating constant values through JavaScript might be fun, the real power of these scripts become apparent when creating functions.
Functions created through JavaScript can be bound to Variable Cards as Operator, which can then be used in Integrated Dynamics logic as usual. For example, you could use them for defining Integrated Tunnels exporter filters, or for calculating complex values such as the median stack size of items in a list.
In this tutorial, we'll create a function that accepts a single Item argument, and returns a Boolean as output. This function will act as a filter operator, which we can use when for example filtering a list of items.
Concretely, we will read the list of items using the Inventory Reader, and Filter it using our newly created function. You can bind the function to a Variable Card by selecting it in the editor and inserting an empty Variable Card, which will store it as Operator.
You are free to use any implementation of the filter function for this tutorial. Hereafter, you can find a valid example script which you are free to copy.
To complete the tutorial, show the result of the filtered list in a Display Panel.
In this example script, you will see that you can invoke built-in methods on items such as isStackable() and stacksize(). More details on which methods are available can be found later in the full manual.
- Operator
- List
- List
Output: List
return item.isStackable() && item.size() >= 16;
}