The Functions node category, contains all those nodes which actually make something happen in your application, like moving objects, destroying objects, settings properties and so on. The Functions category itself is further divided into two subcategories for clarity purposes, those being the Reflected Functions and Implemented Functions categories.
When working with any of the nodes within any of the two above sub-categories, there are two types of Function nodes that will be encountered depending on the functionality of the node.
Callable Functions have no Value Outputs, but rather a number of different Value Inputs for setting the parameters of the function.
Callable Functions always have 1 Flow Input, which simply refers to “Execute” the function, as well as 1 Flow Output which will be called once after the function is done.
Non-Callable Function nodes can easily be identified by their lack of any Flow Input or Flow Output ports. Such non-callable function nodes are always the ones that return a value through a Value Output port and which nodes are usually responsible just for manipulating data, math operations or getting data, rather than actually “making stuff happen” within the application. The Random Range function node is a good example, where it simply returns a random value between Min and Max, rather than actually doing something by itself.
By default, a Non-Callable Function node does not require Flow execution to work and as such they have no Flow Input or Output ports. You simply connect the Value output to some other node you wish to feed the result value and that’s it. Having said that, there are some rare cases in which you would prefer to have control on when the node is called, by explicitly connecting a Flow into the node. In such cases, you can make the node “Callable” by ticking the respective toggle within the node inspector.
Having done that, the node will be converted to a Callable Function as shown above, where 1 Flow input and 1 Flow output will appear. As such, the Value output of the node will only be set whenever you explicitly call the node with a Flow signal.
C# has a language feature called params array. This basically allows a function to take up to any number of optional parameters (of one type), but instead of providing the function in the form of an array or a list, the different parameters can instead be provided separately in one to one basis.
FlowCanvas supports this feature within the editor as well, making it a lot easier to provide multiple function parameters when the function supports the params array feature. When that is the case, a special option in the node’s inspector panel for the function will show to “Expose Parameters”, along with the number of parameters required. Enabling this option, will turn the input parameter port from being an Array type, to multiple separate parameter ports of that type! This makes it easier to connect multiple inputs without the need to create an array!
Following is a node for the “String.Format” function, which supports a string params array as one of the inputs and how changing the type of the params to “Expose Parameters” affects the node.
Another category within the Functions main category, is the Custom Functions. Custom Functions are a great way to create reusable logic within a flowScript. You first need start by creating a Custom Function, through the menu “Functions/Custom/Create Custom Function”. Custom Functions, can have any number of parameters as well as return a value.
Once a custom function node has been created and probably given a good name as well, a new entry in the nodes menu will be made under the “Functions/Custom” category, which will show up your custom function name. That new node (your custom function) can then be used to call the implementation of the custom function from anywhere within the flowScript! Following is a simple example usage.