In a number of other engines I've worked with, including Unreal and Unity, there's been support for not only preprocessor commands, but conditional compilation based on platform. As an example, in Unity, I could do this:
And, the following code, until the
#endif, would only be included if I was compiling for the Windows platform. This is very similar to building with something like
gcc and including the
-D flag for directives, so it isn't new. Additionally, I've noted that when compiling on Godot, I can include the same platform multiple times, allowing for variation.
Suppose I wanted to compile a demo version of my game, using the Godot engine, which only included the first few levels; and a full, premium version, which included the whole thing. I would want both to have feature parity. If I could detect which export template I was using, I could automatically cut the demo off at the correct point, and build the premium version for the full game, at the same time, by selecting "Export All..." compared to manual changes or multiple projects, that's a big win for me.
Currently I'm using the non-Mono version of Godot, and GDScript with occasional GDExtensions C++. GDScripts fundamental design principles preclude a precompiler like C's, but changing a field based on export settings would be more than enough for me. I'm open to C# answers, but I ultimately need to get it to work with GDScript. Can someone help me figure out how to change values based on export template so I can be selective when building my code?