HomeGenie Forum

Development => Bug reporting => Topic started by: bkenobi on July 06, 2014, 12:11:35 AM

Title: C# script compile errors
Post 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?
Title: Re: C# script compile errors
Post by: Void on September 21, 2014, 07:58:43 PM
Try adding this on top of your code:

#pragma warning disable 0168
#pragma warning disable 0219
#pragma warning disable 0414

:)
Title: Re: C# script compile errors
Post by: Gene on September 21, 2014, 10:55:11 PM
Thanks this works!

g.
Title: Re: C# script compile errors
Post by: Void on September 22, 2014, 11:43:03 PM
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
Title: Re: C# script compile errors
Post by: bkenobi on September 23, 2014, 12:16:30 AM
Does this work for scripts or does it have to put in the HG compiled code?!
Title: Re: C# script compile errors
Post by: Void on September 23, 2014, 12:26:46 AM
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:

Code: [Select]
#pragma warning disable 0168
#pragma warning disable 0219
#pragma warning disable 0414
var foo=1;
Title: Re: C# script compile errors
Post by: bkenobi on September 23, 2014, 12:36:23 AM
Excellent, I'll add that to my code when debugging.  Thanks!