This page summarizes some of the peculiar behaviors of S#. In each case, there is a straightforward workaround.

Local and global variables can conflict and produce unexpected results.

The variable msg inside the function is not explicity declared or initialized, so it gets its initial value from the global variable of the same name; however, modifying the variable does not change the global variable declared outside the function.

 var msg = "Hello ";
 function test()  {
   msg += "World!";
   DEBUG("Inside test: " + msg);  
 }
 
 DEBUG("Before test: " + msg);
 test(); 
 DEBUG("After test: " + msg);
 					
Produces:

In this second example, the function uses the global keyword to indicate the msg variable is global; however, defining a new local variable with var msg; sets the global msg to null.

 var msg = "Hello ";
 function test() global(msg) {
   var msg;
   msg += "World!";
   DEBUG("Inside test: " + msg);  
 }
 
 DEBUG("Before test: " + msg);
 test(); 
 DEBUG("After test: " + msg);
 					
Produces:

Workaround:

  1. Explicitly declare and initialize local variables with var.
  2. If you need access to global script variables within a function, use the global keyword (consult See Also).
  3. Consider using DataHub WebView dynamic global variables instead of S# script global variables.

String literals "true" and "false" are considered boolean literals.

The expected behavior of this code:

 DEBUG("true is " + "true");
 var t = "tr" + "ue";
 DEBUG("t is " + t);
 
 if (t == "true")
   DEBUG("true");
 else
   DEBUG("false");  
 					

...is to output these three messages:

 true is true
 t is true
 true
 					

Instead, it produces this output.

The string literal "true" is treated as the boolean literal true, which actually has a .NET string value of "True".

Further, the code generates a RunTimeError when comparing t to "true" because the S# script engine is unable to compare a string to a boolean.

Workaround: Do not use the string literals "true" and "false". You can safely use "True" and "False".