HomeGenie Forum
Development => Bug reporting => Topic started by: bkenobi on July 06, 2014, 12:11:35 AM
-
I have noticed that when I assign a variable bu do not use it, I get an error that keeps the code from compiling. I understand that this could be a warning, but why does it need to be an error that stops compile? I have the logging code in my scripts that I sometimes disable and with this error, I have to disable every single instance of logging variables depending on what I'm doing. It would be nice if this could be left at a warning level rather than error so that the compile could continue. Having an unused assigned variable is poor form for a final release of a code package, but why is it an issue for a script?
-
Try adding this on top of your code:
#pragma warning disable 0168
#pragma warning disable 0219
#pragma warning disable 0414
:)
-
Thanks this works!
g.
-
Hi!
#pragma warning disable
Without any error code, will disable all compiler warnings (Not only those associated with variables unused)
#pragma warning restore, restores all warnings and you can mix them as u want in your code. For example you can disable warnings in some function but enable them for the rest of your code.
Better (And original) explanation is here :
http://msdn.microsoft.com/en-us/library/441722ys%28VS.80%29.aspx (http://msdn.microsoft.com/en-us/library/441722ys%28VS.80%29.aspx)
Warning codes list :
http://msdn.microsoft.com/en-us/library/ms228296.aspx (http://msdn.microsoft.com/en-us/library/ms228296.aspx)
Regards! :D
-
Does this work for scripts or does it have to put in the HG compiled code?!
-
You can use in any C# source code (HG C# Scripts in this case).
This command tells the compiler to ignore warnings when you compile/run your C# code. :)
For example in HG C# Scripts, lets the declaration of unused variables (Your code, your memory ...) :)
This code sould compile without problems:
#pragma warning disable 0168
#pragma warning disable 0219
#pragma warning disable 0414
var foo=1;
-
Excellent, I'll add that to my code when debugging. Thanks!