RSS
 

#32: Tips for XML scripts

03 Sep

Our customized XML scripts (see post#31) is based on C++, so C++ rules apply. I will discuss some common mistakes here:

Variable scope:

The following script is wrong. “$checkori” will return Null since “script:$path” is Null. The reason is the scope of “$path” is limited inside the If statements.

		
			
			
			
			
		
		
			
			
		

		

The correct way of the above script is as below: set initialize value to “$path” outside the If statements.

		
		
			
			
			
		
		
			
			
		

		

Data Type:

The following script is wrong. An error will pop up when running the script since the original data type of “$check” is integer(ulong). Integer parameter can not multiply float(double) 40.3696.

			
			
			

The correct way of the above script is as below: change the data type of “$check” to double before the multiply.

			
			
			
			

Compare float(double) data:

The following script can go wrong since both “$target” and “$check” are float(double) data. Say we set “$target” to 0.5, then we may expect “$target”=”$check” since the display value of “$check” is 0.5, but actually they are not equal since the real value of “$check” is 0.50000000000002.

		
			
			
			
			
			script:$logmsg
		

The correct way of the above script is as below: compare the difference between “$target” and “$check” with a very small decimal number, such as 0.0001.

		
		
				
			
			
			
			
			script:$logmsg
		
 

Tags: , , , , , , , ,

Leave a Reply