Skip to content

Instantly share code, notes, and snippets.

@OverlordZorn
Last active May 8, 2025 12:52
Show Gist options
  • Save OverlordZorn/08bc12a898b13ee77003d10a88505715 to your computer and use it in GitHub Desktop.
Save OverlordZorn/08bc12a898b13ee77003d10a88505715 to your computer and use it in GitHub Desktop.
Quick Explainer on A3 Preprocessor commands / Macro's

So. What are Macro's?

Marcos are a tool that can be used to "automate" the creation of parts of code. This can be simple names for global variable like ace_wardrobe_globalVariable with something like GVAR(globalVariable) but also more complex, multi-line macros.

What are Preproccor Commands?

Preprocessor Commands are commands that are being interpretated and "converted" during the process of interpretating SQF code.

see the biki for more details https://community.bistudio.com/wiki/PreProcessor_Commands

One of the core parts of this is the command #define, which defines a "definition" to a KEYWORD.

In SQF, you would assign a value to a variable like this

private _variable = "value";
systemChat _variable;

this will output "value" via systemChat.

With Macro's it a similar concept.

#define KEYWORD "definition"
systemChat KEYWORD; // will be interpretated as: systemChat "definition"

this will output "definition" via systemChat.

#define KEYWORD 9000

private _value = KEYWORD;
hint str _value; // Will hint "9000"

When such a preprocessor KEYWORD is detected, it will be replaced with whatever it has been #define'd as

Preprocessor command with "input"

One can also define Macro's with a "variable" input.

#define ADD(A,B) A = A + B

private _value = 10;
ADD(_value,20);

hint str _value; // Will hint "30"

How does sth GVAR() work?

GVAR() is a macro defined from CBA and references uses multiple other Macros.

#define GVAR(var1) DOUBLES(ADDON,var1)

DOUBLES(A,B) connects two inputs like this DOUBLES(ace,wardrobe) -> ace_wardrobe using the preProcessor command ## (see wiki).

#define DOUBLES(var1,var2) var1##_##var2

ADDON is a #define ADDON DOUBLES(PREFIX,COMPONENT)

PREFIXis defined by the mod maker within the mod's main addon folder's script_mod.hpp´file.

COMPONENT is defined by the mod maker within the addon's script_component.hpp file.

Multi-Line Macro's

One can also define multi-line Macro's by adding a \ at the end of the line on every line but the last.

#define CONFIG_HELPER(classname,attribute,value)\
class classname {\
  attribute = value;}\
}

It is best practise to not put the final ; into a macro and instead put it behind the macro

With a Multiline Macro, one can make busy config work really simple and easy if there is a repeatable pattern.

CONFIG_HELPER(rhs_helmet,bulletproofness,9001);
CONFIG_HELPER(rhs_helmet_1,bulletproofness,9001);
CONFIG_HELPER(rhs_helmet_2,bulletproofness,9001);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment