GDScript → Add conditional compilation directives #4023
Replies: 4 comments 4 replies
-
One method that works quite well already to achieve this kind of thing is features. You can set different features per export, and check whether those are set. There is even a default feature set that tells you if you are running in debug mode or not, which can be very useful. |
Beta Was this translation helpful? Give feedback.
-
For the sake of completion, I'm going to mention the proposal for conditional compilation with Feature Tags here, as well. |
Beta Was this translation helpful? Give feedback.
-
Useful but bad idea that reduces code readability. Makes it difficult to read code written by others. I love the philosophy that less keyword is better. Go language should be taken as an example |
Beta Was this translation helpful? Give feedback.
-
I made a plugin: dalexeev/gdscript-preprocessor. |
Beta Was this translation helpful? Give feedback.
-
C has
#if
that you can use to perform conditional compilation.It is useful to make a separation between "testing mode" and "normal mode".
The core idea is to have some lines of codes (checks, print statements and so on) that would be ignored when exporting the project by disabling it →
#TESTING_MODE = false
Using another syntax compatible with GDScript.
Another way could be use a keyword to "mark" blocks of code.
Could be by creating some "special"
bool
variable and then use it to "mark" blocks of code.Example:
The difference with a normal
bool
would be that it tells the compiler to ignore it if false. Useful to release/export and so on.It would be declared mostly inside Autoloads.
(Probably something like that had been already proposed.)
Beta Was this translation helpful? Give feedback.
All reactions