more G-Labs products

Author Topic: C# script compile errors  (Read 2344 times)

July 06, 2014, 12:11:35 AM
Read 2344 times

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
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?

September 21, 2014, 07:58:43 PM
Reply #1

Void

  • *
  • Information
  • Newbie
  • Posts: 18
Try adding this on top of your code:

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

:)

September 21, 2014, 10:55:11 PM
Reply #2

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Thanks this works!

g.

September 22, 2014, 11:43:03 PM
Reply #3

Void

  • *
  • Information
  • Newbie
  • Posts: 18
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

Warning codes list :
http://msdn.microsoft.com/en-us/library/ms228296.aspx

Regards! :D

September 23, 2014, 12:16:30 AM
Reply #4

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Does this work for scripts or does it have to put in the HG compiled code?!

September 23, 2014, 12:26:46 AM
Reply #5

Void

  • *
  • Information
  • Newbie
  • Posts: 18
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;
« Last Edit: September 23, 2014, 12:32:46 AM by Void »

September 23, 2014, 12:36:23 AM
Reply #6

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Excellent, I'll add that to my code when debugging.  Thanks!