This page provides a detailed overview about the Function Node, which will be implemented in Intera 5.5.


Contents


Node Description


Function 5 1.png


Function Node


This node provides a coding interface for performing simple calculations or String operations using native JavaScript code with:

  • Variables: Boolean, Integer, Float and String, Arrays and Structures.
  • JSON parsing and output.

 

Node Type


Primitive - Cannot have children.


Node Editor


Function step 2.jpg Function step 1.jpg


  • Snippet select

Select a snippet from available snippets

Snippet Symbol (Or “+” Symbol)'

Create a new or Edit selected snippet

  • TEST Button

Test selected snippet

  • Inputs

link user variables or other shared data to be input to your snippet

  • Inputs

link user variables or other shared data to be output from your snippet

  • Documentation

Inherits documentation from the snippet editor

 

Snippet Editor Window


Function step 3.jpg


Function step 4.jpg


  • Save Button

save your snippet

  • Name

A user friendly name of your snippet

  • Define Parameters - In:
    • Add a new input parameter with the “+” sign
    • give a name to the parameter (can start only with a letter, not a number).
    • Select the parameter’s type: (String, Boolean, Integer, Float, Length, Linear Force, Torque, Speed, Time, Mass, Angle, Acceleration, Stiffness, Voltage, Percentage)
  • Define Parameters - Out
    • Add a new ouput parameter with the “+” sign
    • Give a name to the parameter (can start only with a letter, not a number).
    • Select the parameter’s type: (String, Boolean, Integer, Float, Length, Linear Force, Torque, Speed, Time, Mass, Angle, Acceleration, Stiffness, Voltage, Percentage)
  • Code Window

In this window you can add your code (between “let” and “return” commands). The window will show any syntax errors interactively with “i” and “x” icons in the problematic line.

  • Dark\Light Toggle

Switch the code window colors between dark scheme and light scheme.

  • Validate snippet

A tool to test and validate your snippet with test data you can type. A pass will result in green “V” and a fail in red “X”.

  • Documentation

Document in free text what this specific snippet does. 


Example


  • Create new user variables “min_var”, “max_var” and “random_var” (all should be defined as integers).
  • Create new snippet (using Extension Gallery or Function node) with these settings


Function step 5.jpg


The code should be:


function RandomMinAndMax() {
    let min, max;
    let random;
    random = Math.floor(Math.random() * (max - min + 1) ) + min;
    return {
random, // int
    };
}


  • Add a Function node with these settings


Function step 6.jpg


  • Add a Set To node with these settings


Function step 7.jpg


  • Add Wait node with 1 second.
  • The behavior tree should be like this:

Function step 8.jpg

This task is generating a new random number between 0 and max_var (which is incrementing during the task) every one second.