
Flowgraph modules
The flowgraph module system allows flowgraphs to be exported as a module that can be triggered from another graph.
By creating modules, we can reuse logic in multiple levels without having to maintain several versions of the same graph. It's also possible to send and receive unique data to and from the modules, allowing dynamic logic in a very modular manner.
Creating a module
To start with creating your own module, open the Flowgraph Editor and select File | New FG Module... | Global:

In the resulting Save dialog box, save the module with a name of your choice. You'll then be shown the default view of a module:

The module contains two nodes by default; Module:Start_MyModule and Module:End_MyModule.
- Module:Start_MyModule contains three output ports:
- Start: This is called when the module is loaded
- Update: This is called when the module should be updated
- Cancel: This is called when the module should cancel, and it is connected to the Cancel input of Module:End_MyModule by default
- Module:End_MyModule contains two input ports:
- Success: This should be called when finalizing the module, and passes a "success" status to the caller
- Cancel: This is used to end the module prematurely, and passes a "cancelled" status to the caller
Finally, to fill your module with logic, simply connect the Start output port to your logic nodes.
Calling a module
To call an existing module, find the relevant node in the Module node category. The call nodes are named as Module:Call_<ModuleName>
:

Then simply trigger the Call port to activate your module, and Cancel to abort it.
Module parameters/ports
From what we've learned previously, we're able to call modules with a void port. This is not optimal in all cases, as you might want to pass additional data to the module.
To allow this, the module system exposes module parameters. By selecting Tools | Edit Module... in the Flowgraph Editor, we can add a set of parameters to our module:

This action opens the Module Ports window, which allows us to add and remove ports:

By selecting New Input or New Output, we'll be able to add new ports that can be used when activating the module.

Adding a new input or output will automatically output its Module:Start_MyModule or Module:End_MyModule node, allowing you to receive the data:

All Module:Call_MyModule nodes are also updated automatically, giving you access to the new parameter right away:
