Scripting: Preprocessor Directives – Arma Reforger

From Bohemia Interactive Community
Jump to navigation Jump to search
(Page creation)
 
 
(One intermediate revision by the same user not shown)
Line 4: Line 4:


For use cases, see e.g {{Link|Arma Reforger:Scripting Temporary Feature|Scripting Temporary Feature}}.
For use cases, see e.g {{Link|Arma Reforger:Scripting Temporary Feature|Scripting Temporary Feature}}.
{{Feature|informative|See also {{Link|Arma Reforger:Scripting: Preprocessor Macros}}.}}
{{Clear}}
{{Clear}}
{| class="wikitable valign-top"
{| class="wikitable valign-top"
Line 29: Line 32:
|
|
=== #ifndef ===
=== #ifndef ===
| Open a preprocessor scope that is considered if the provided flag is '''not''' defined. The scope must be ended by #endif (see below).
| Open a preprocessor scope that is considered if the provided flag is '''not''' defined. The scope must be ended by {{hl|#endif}} (see below).
| <enforce>
| <enforce>
#define MY_FLAG
#define MY_FLAG
Line 41: Line 44:
|
|
=== #else ===
=== #else ===
| Add a preprocessor scope that is of the opposite condition of the current {{hl|#ifdef}}/{{hl|#ifndef}}. The scope must be ended by #endif (see below).
| Add a preprocessor scope that is of the opposite condition of the current {{hl|#ifdef}}/{{hl|#ifndef}}. The scope must be ended by {{hl|#endif}} (see below).
| <enforce>
| <enforce>
#ifdef MY_FLAG
#ifdef MY_FLAG

Latest revision as of 16:01, 30 June 2024

Preprocessor directives allow to determine preprocessor behaviour, e.g ignoring blocks of code depending on certain conditions.

For use cases, see e.g Scripting Temporary Feature.

Directive Description Example

#define

Define a flag. A flag is either defined or not.
A flag can be determined outside of the code; see Startup Parameters - scrDefine.
#define MY_FLAG

#ifdef

Open a preprocessor scope that is considered if the provided flag is defined. The scope must be ended by #endif (see below).
#define MY_FLAG #ifdef MY_FLAG Print("Flag is defined"); #endif

#ifndef

Open a preprocessor scope that is considered if the provided flag is not defined. The scope must be ended by #endif (see below).
#define MY_FLAG #ifndef MY_FLAG Print("Flag is not defined"); #endif

#else

Add a preprocessor scope that is of the opposite condition of the current #ifdef/#ifndef. The scope must be ended by #endif (see below).
#ifdef MY_FLAG Print("Flag is defined"); #else Print("Flag is not defined"); #endif

#endif

Close a preprocessor scope - see #ifdef and #ifndef above. See #ifdef and #ifndef above.

#include

Include another file. The effect is as if the other file's content was copy-pasted at this exact #include location.
// FileToInclude.c protected static const string MY_PRINT = "Hello there";

class SCR_ScriptedClass { #include "scripts/Game/FileToInclude.c" void ShowMessage() { Print(MY_PRINT); } }