Webtags (preserving history): Difference between revisions

m
Line 189: Line 189:
*To use the value from a tag as an integer in JavaScript assigning code you need to use a  
*To use the value from a tag as an integer in JavaScript assigning code you need to use a  
<pre>integer_variable_name=parseInt(string_variable_name,10)</pre> type conversion
<pre>integer_variable_name=parseInt(string_variable_name,10)</pre> type conversion
*Alternatively, in most script languages, apply '*1', i.e. multiply by one, to implicitly convert the tag from string to base 10 number.
*To use a value from a tag as a floating point number in JavaScript you need to use <pre>parseFloat(string_variable_name)</pre> otherwise you will find any attempt to add something to it results in a concatenation because JavaScript uses "+" for two purposes and concatenation takes precedence over arithmetic adding!
*Another alternative is to add zero when a web tag is being assigned to a script variable, this is used in scripts where the web tag being used is not available in all versions of Cumulus. Adding 0 means that if the web tag is not recognised, the script is still able to give a variable in its language some value and won't fail because that variable is undefined. If the web tag is available, the true value of that web tag is still assigned to the variable.
*Alternatively, in most script languages, apply ' * 1', i.e. multiply by one, to implicitly convert the tag from string to base 10 number.
*Another alternative is to add zero when a web tag is being assigned to a script variable, this is frequently used in scripts where the web tag being used is not available in all versions of Cumulus, because Cumulus does not implement the concept of null values and often zero is used when a true value is not available because that sensor is not installed for example. Adding 0 means that if the web tag is not recognised, the script is still able to give a variable in its language some value and won't fail because that variable is undefined. If the web tag is available, adding zero does not prevent the true value of that web tag being assigned to the variable.


== Web Tag Differences Between Cumulus 1 and MX builds ==
== Web Tag Differences Between Cumulus 1 and MX builds ==
5,838

edits