Using Preprocessor Symbols
Using Preprocessor Symbols
Warning: Solved, possibly duplicate post. Will take down on request.
Question: How do I set a variable like XBOX, XNA or MONOGAME true or false?
Elaboration: So there is this neat thing in c# that is the '#' (edit: preprocessor directives).
Used by me to divide my code up into regions:
#region SomeRegion
void Function() lalalala
#endregion
And by code I've seen to check platforms or lower level stuff:
#if MONOGAME
do moar stuf;
#endif
#if EDITOR (unity)
some editor specific stuf
#else
runtime specific stuff
#endif
But I want to know if I could do something like:
#MONOGAME = true
(I have tried that)
Background: I'm trying to import farseer into a monogame project. the #if !MONOGAME
statement is not triggering false, and so it defines Vector2 along with xna's vector2, and so i want to manually set MONOGAME to 'true'.
#if !MONOGAME
1 Answer
1
Thanks @RonBeyer for pointing me in the right direction.
After a bit of research I found what I needed, a global preprocessor symbol.
This will trigger #if xyz
queries true.
#if xyz
You can create a global one in project properties -> build -> general -> conditional compilation symbols.
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
These are called preprocessor directives, and are exactly what they sound like. They adjust the code before the code is compiled, so the code may not make it into compiled assembly. You can't set those from code.
– Ron Beyer
Sep 8 '18 at 13:49