Conditional compilation
Conditional compilation lets you write code that adapts to statically known information like presence or absence of other mods. For example, you might want to use a feature from another mod, but only if the user has that mod installed. Or you might want to avoid a conflict with another mod by changing your code depending on whether that mod is present or not.
To use conditional compilation, you need to use the @if
annotation followed by a condition before the code that you want to include or skip. Here’s a simple example:
The condition in the @if
annotation can only consist of:
true
orfalse
logical operators (&&, ||, !, ?:)
the
ModuleExists
function, which returns true if a mod name exists and false otherwise
Since v0.5.18, you can use @if
annotation on class members (fields and methods) like in the example above.
Last updated