Module
- Last UpdatedDec 16, 2023
- 4 minute read
A Module node is used to instance a module definition created by a defmodule. A Module instance will work as an interface to the content included in the module definition and will expose the configuration, input, and output contained in the defmodule as its own fields.
In general terms, it's possible to create multiple instances of Module nodes, based on the same defmodule.
Platform support
This element is fully supported on XR-Windows, XR-Portable Windows, XR-Portable iOS, XR-Portable Android, and XR-P Hololens platforms.
|
XR-WIN |
XR-P-WIN |
XR-P-IOS |
XR-P-AND |
XR-P-WASM |
|---|---|---|---|---|
|
Full support |
Full support |
Full support |
Full support |
Full support |
|
|
|
|
|
|
Instancing a Module
To successfully instantiate a module, the following elements must be specified:
-
Module node unique name.
-
Module node moduleType that must match the name of an available defmodule name.
-
Module configuration properties, based on the corresponding defmodule configuration elements. Those tagged as mandatory cannot be missed, or the Module creation will fail.
-
Optionally, it's possible to specify the version of the module definition to be used for the instance.
Manifest file
When creating a module, the manifest for the specified module type will be searched in the project folders.
-
The manifest.xml can be contained in a specified pak, or in a specified folder, both configurable using the pak field.
-
The default search path is .\GameData\Modules\%MODULE TYPE%\manifest.xml
-
The manifest should contain the defmodule of the specified module type.
-
If a module manifest is not found and the defmodule was not already parsed earlier in the chain of script inclusions, the Module instancing will fail.
Note that only the first referenced version will be loaded and all other instances will use the same.
Code example
This is a code example of a Module definition. Note that only the defmodule configuration is set and they are assigned using their name.
<!-- defmodule definition -->
<defmodule name="amodule" version="1.0.0" >
<configuration name="param1" isMandatory="true" type="sstring" />
<configuration name="param2" type="sstring" value="DEFAULT_VALUE" />
<input name="setText" type="sstring" />
<output name="getText" type="sstring" />
<include name="modules/amodule/amodule_logic.xml" />
</defmodule>
<!-- Module instancing samples -->
<Module moduleType="amodule" name="instance1" param1="This is a text" />
<Module moduleType="amodule" name="instance2" param1="This is another text" param2="Not a default Text" />
Referencing a Module instance
When there is a need to reference a Module instance with a route or within a command or a coroutine, the instance fields will need to start with a prefix.
Prefixes
|
conf_ |
For module definition configuration elements. |
|
input_ |
For module definition input elements. |
|
output_ |
For module definition output element. |
Code example
This is a code example showing field prefixes.
<!-- this sample refers to the amodule module definition in the previous paragraph -->
<Module moduleType="amodule" name="instance1" param1="This is a text" />
<route from="instance1.output_getText" to="cmd_write.execute" />
<Command name="cmd_write" >
<set name="instance1.input_setText" value="new Text" />
</Command>
Fields
These are the fields for Module node command.
|
Fields |
Type |
Use |
Default value |
Description |
|
name |
sstring |
Mandatory |
Instance name for the module. |
|
|
moduleType |
sstring |
Mandatory |
|
Defines the module definition to use to create the instance. |
|
pak |
sstring |
Optional |
.\GameData\Modules\%module type% |
If this field is set to a .pak file path, the pak will be loaded before the manifest file search. This field can point to a folder too. In that case, the manifest will be searched for in the specified folder. |
|
version |
sstring |
Optional |
Specifies the preferred module definition version to use. |
|
|
XXX (configuration) |
Depends on the corresponding module definition configuration element. |
Mandatory, if the configuration element is set as mandatory. |
Depends on the corresponding module definition configuration element. |
Configuration elements present in the module definition should be set at Module node instancing using their name. If the configuration is set as mandatory, it must be included in the Module node instancing. |
|
conf_XXX |
Depends on the corresponding module definition configuration element. |
Realtime only |
|
Can be used to read the value stored in the configuration. This value should not be changed at runtime. |
|
input_XXX |
Depends on the corresponding module definition configuration element. |
Realtime only |
|
Can be used to set an input value on the module. |
|
output_XXX |
Depends on the corresponding module definition configuration element. |
Realtime only |
|
Can be used to read an output value from the module. This should be treated as a read-only field. |