Define instruction
Repetitive SDL fragments can be described using the define instruction for further multiple calls in the required places.
Template for the define instruction
Template for the
defineinstruction(define "name" [code])
"name" - the identifier for the define instruction, enclosed in double quotes.
[code] - an optional SDL fragment that will be inserted wherever the define is called.
The parentheses (...)are mandatory and encapsulate the entire instruction, ensuring that the parser SDL recognizes and correctly processes the definition as a single cohesive unit.
Arguments in a define instruction
The SDL fragment can contain arguments, the values of which usually change from one call to another.
Calling a define instruction
The define instruction is called by its name, which is enclosed in double quotes.
Template for calling a
defineinstruction
[args] - arguments are optional
When calling a define instruction that does not require arguments, you simply use the name of the defined term within the SDL script where you need the defined contents to appear. The syntax is straightforward; since no arguments are involved, you only need to reference the defined name within double quotes.
When calling the instruction, values for named arguments may be empty.
Nested define instruction
Nested define instructions allow you to build complex configurations by combining simpler defined components into more sophisticated structures. Here's how you can define and use nested define instructions in SDL
Defining basic components
Define some basic components that we'll use in our nested setup.
Creating a nested
defineinstruction
Next, you can define a more comprehensive setup that includes these previously defined components. This is where the nesting comes into play.
Calling a nested define instruction
Finally, you use the nested definition in your SDL script where needed, just like any other defined instruction
Benefits of nested define instructions
Modularity You can create modular blocks of SDL that can be reused and combined in various ways.
Maintainability It’s easier to update and maintain your SDL scripts, as changes to a single defined block will propagate wherever it is used.
Clarity Nested definitions can help clarify the structure of complex setups by breaking them down into manageable parts.
Nested define instructions thus provide a powerful way to structure and simplify complex SDL configurations in a scalable and maintainable manner.
Using arguments as a part of a define instruction name
Using arguments as a part of define instruction name can offer several benefits in scripting:
to create generic instructions that dynamically call relevant content definitions based on the arguments passed;
to reduce a code duplication;
to disable one or several nested instructions if it is necessary
The empty define instructions are used when it is necessary to disable one or several nested instructions. In this case, an argument is often used in the name of the nested instruction when calling.
More examples
An alternative name for the define instruction is macro.
Additionally, you can explore other types of instructions.


Last updated