Integrated Dynamics - On the Dynamics of Integration

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
FilterfilterFilter a list of elements by matching them all with the given predicate.
  • Operator
  • List
  • List
Global name: operatorFilter(OperatorList) → ListMethod name: Operator.filter(List) → List
Aspect
ItemsGet a list of the items in the inventory

Output: List

    function filterItemMethods(item) {
      return item.isStackable() && item.size() >= 16;
    }
    Advancements
    • Overpowered item list filteringFilter a list of items read from a chest using a script-based function.
    Rewards
    Scripting Disk4
    Variable Card16