A Module is an exported Flow Graph that can be loaded and called from another Flow Graph at any point during the game session.
Any Flow Graph can be converted to a Module simply by creating a new module in the Flow Graph Editor, and copying the Flow Graph contents to this new module.
The advantages of using Modules:
- Same Flow Graph can be used in multiple levels, but only exist in one location.
- Modules can receive unique input values from their caller, allowing them to be very robust.
- Modules can return unique output values to their callers, allowing them to be used in many different situations.
- Modules are instanced, meaning that multiple copies of the same module can be active simultaneously, but running with different inputs
Converting a Flow Graph to a Module
A Module is just a special flavor of a Flow Graph. This means ANY Flow Graph can become a Module with a few simple modifications made to it.
First create a module by selecting File -> New FG Module... in the Flow Graph Editor:
or right-click on the FG Modules item in the Flow Graph overview and choose New FG Module from the context menu:
Save the module in either of these two locations:
Game/Libs/FlowgraphModules/(for a global module accessible in all levels).
Game/Levels/<levelfolder>/FlowgraphModules/(for a level specific module).
Your new module will appear in the Flow Graph overview:
The new module will already contain two nodes: Module:Start_<YourModuleName> and Module:End_<YourModuleName>. These are specifically created for this module, and cannot be removed.
Start node output:
- Start - Called when Module is loaded. Treat this like you would the Misc:Start Node.
End node inputs:
- Success - call this to end the module and pass a 'success' status back to the caller.
- Cancel - call this to end the module and pass a 'canceled' status back to the caller.
Deleting a Module
If you want to delete a specific Module you can right click on the Module name in the FG Modules list.
If you delete a Module it will also delete the saved XML file.
Saving a Module
To save your Flow Graph so that it can be used as a Module, all you need to do is bring up your Flow Graph in the Flow Graph Editor, and select Save from the File Menu. There are multiple locations where you should save the Flow Graph , depending on how you want to use it:
This is your Global Modules folder. Save your Module here if you want to use it in multiple levels.
This is your Level Modules folder. Every Level can have their own Modules folder. Save your module here if you want to use it only in one particular level.
When loading a Module, the system will first check the current level's FlowgraphModules folder. If the Module is not found there, it will then look in the Global FlowgraphModules folder. This gives you the potential to overwrite a Global Module with a Level-Specific Module if you wish.
Calling a Module from Flow Graph
So now we have this Module ready to be used in our level. To call the Module, all you need to do is use the Call node specific to your module. It will be named Module:Call_<YourModuleName>:
- Call - Call to load the Module and begin its execution.
- Done - Called when the Module returns with a Success status.
- Canceled - Called when the Module returns with a Fail status.
Custom Module Ports
You can also customize the inputs and outputs for each module, to pass extra data back and forth. To do so, use the Tools -> Edit Module menu option in the Flow Graph editor:
This brings up a dialog which allows adding inputs and outputs:
Clicking OK on this dialog will regenerate the module nodes (Start, End and Call) with the new inputs and outputs:
All inputs passed to the Call node will activate the corresponding outputs on the Start node, and similarly inputs to the End node will be passed back to the Call node when Success or Cancel are activated.
To access the Flow Graph Module System from outside you can use the IFlowgraphModuleManager interface.
In order to get an overview of all currently available Flow Graph Modules and/or see currently active module instances it is possible to use the following console variables:
- fg_debugmodules 0/1/2 - 0: Disabled / 1: Shows a list of all currently available modules / 2: Shows a list of all currently available modules and active module instances
- fg_debugmodules_filter "filterstring" - "filterstring" can be used to only show specific modules