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 define instruction

(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.

circle-exclamation

Arguments in a define instruction

The SDL fragment can contain arguments, the values of which usually change from one call to another.

chevron-rightExample of a define instruction without argumentshashtag
(define "seismic_custom"
    {damage seismic {energy 10} {radius 8}}
)
chevron-rightExample of a define instruction with numeral argumentshashtag
(define "seismic_custom"
    {damage seismic {energy %0} {radius %1}}
)
chevron-rightExample of a define instruction with named argumentshashtag

Calling a define instruction

The define instruction is called by its name, which is enclosed in double quotes.

Template for calling a define instruction

  • [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.

chevron-rightExample of calling a define instruction without argumentshashtag

Source SDL fragment:

In this example, whenever "seismic_custom" is used in the SDL script, it will insert the set of commands defined under “seismic_custom”description. Since no arguments are used, you don't need to enclose anything other than the double-quoted name in parentheses.

Result SDL fragment:

chevron-rightExample of calling a define instruction with ordinal argumentshashtag

At the first call of the "seismic" instruction, the arguments take the following values: %0=10, %1=8, %2=3000 At the second call of the "seismic" instruction, the arguments take the values: %0=45, %1=300, %2=3000 The result of the "seismic" instruction call will be SDL, containing at the call sites the lines:

chevron-rightExample of calling a define instruction with named argumentshashtag

The result of the "seismic" instruction call will be SDL, containing at the call sites the lines:

When calling the instruction, values for named arguments may be empty.

chevron-rightExample of calling a define instruction with an empty argumenthashtag

Source SDL:

Result SDL:

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

  1. Defining basic components

Define some basic components that we'll use in our nested setup.

chevron-rightExample hashtag
  1. Creating a nested define instruction

Next, you can define a more comprehensive setup that includes these previously defined components. This is where the nesting comes into play.

chevron-rightExample of a nested define instructionhashtag

In this nested define, "StandardSceneSetup" calls both "AmbientLight" and "SetBackgroundColor" within its definition.

  1. Calling a nested define instruction

Finally, you use the nested definition in your SDL script where needed, just like any other defined instruction

chevron-rightExample of calling a nested define instructionhashtag

Calling the "StandardSceneSetup" will execute all the commands in "StandardSceneSetup", including the nested definitions of "AmbientLight" and "SetBackgroundColor", along with any additional commands defined directly within "StandardSceneSetup"

Result SDL:

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.

chevron-rightExample of using an empty define instructionhashtag

In this example, we are dealing with dynamically selecting and invoking specific content definitions based on arguments provided to a define instruction.

  • "content_none" is an empty definition, used when no content is necessary.

  • "content_v" and "content_v_officer" include specific data content (data1 and data2 respectively).

  • "set_default" demonstrates a dynamic content selection mechanism using the argument %con. This setup allows the set_default instruction to dynamically call one of the content definitions based on the suffix provided.

  • The calls to "set_default" pass different arguments (none, v, and v_officer) to the %con argument, determining which of the "content_*" definitions is executed. For instance, ("set_default" con(none)) will call "content_none".

More examples

An alternative name for the define instruction is macro.

chevron-rightExample of a basic macro with a basic set of parametershashtag
chevron-rightExample of a macro with a standard set of settingshashtag
chevron-rightExample of a top-level macro that uses standard settingshashtag

The result of calling the set_v instruction will be the final setting for the PZ1b

circle-info

If you have difficulties understanding the terminology and the essence of the instruction description, please refer to the article Basic knowledge about configuration filesarrow-up-right.

Additionally, you can explore other types of instructions.

Cover

Include instruction

Cover

Mod instruction

Last updated