Creating template definitions
- Last UpdatedApr 24, 2024
- 1 minute read
A template name must be unique inside the script.
Create a template definition
-
When creating a template, write the template as a normal plain script block. Put this code block inside a deftemplate node.
-
Identify the script elements to be parametrized.
-
Replace the elements with placeholders.
Placeholder requirements
-
Use the %placeholder% syntax.
-
Do not include special characters or blank spaces.
-
Give each placeholder a unique name inside the deftemplate script block.
Code example
This is a code example for deftemplate.
<deftemplate name="vapore">
<animationtexture name="txt_%mesh%" texture="animt_%mesh%" clone="AnimVapore" assignToMesh="%mesh%" />
<timer name="tim_%mesh%" randomRange="8 20" loop="true" start="true"/>
<route from="tim_%mesh%.cycle" to="txt_%mesh%.restart"/>
</deftemplate>
Guidelines for developing templates
-
Put template code into separate files to be included. Ideally, each template has its own file, which helps to create libraries of templates.
-
Avoid referencing directly inside the template code node any names that are defined outside the template itself because this makes it less portable. Use placeholders to parameterize these references.
-
Assign self-explanatory names to placeholders so that you or others can quickly understand the purpose of the template.