Variables and Types

Variables in TrafficScript can contain data of various types: integer, floating point (double) or string. TrafficScript automatically casts (converts) values and variables into the correct type when you evaluate an expression or call a function:


Value       Cast to integer   Cast to double   Cast to string  
14 (integer) 14 14.0 "14"
3.25 (double) 3 3.25 "3.25"
3.75 (double) 4 3.75 "3.75"
"abcde" (string) 0 0.0 "abcde"
"3.25" (string) 3 3.25 "3.25"
"3.75" (string) 4 3.75 "3.75"
"14str" (string) 14 14.0 "14str"
"3.2.7" (string) 3 3.2 "3.2.7"

Strings and doubles are rounded up or down to the nearest integer value when they are cast to integers.

$int = 10;
$double = 2.71828;

string.len( $int ); # casts to string, returns 2
string.len( $double ); # casts to string, returns 7

# Set $string to "10, 2.71828"
$string = $int . ", " . $double;

# Convert $string to a number, and add 4:
$r = $string + 4; # $r is 14

In a mixed-type operation such as a compare, where all types are allowed:

  1. If either operand is a double, both operands will be converted to doubles, else:
  2. If either operand is an integer, both operand will be converted to integers, else:
  3. Both operands are strings, in which case a string operation is used.
Owen Garrett [Zeus Dev Team] 01 July 2005  Permalink  
Leave a comment ...
Your email address will not be displayed.
Your URL will be displayed.
This public messageboard is not a forum for technical support. To report technical support problems, please contact our dedicated Support team using the instructions at the bottom of this page.
Options:
 
(Line breaks become <br />)
(Set cookies for name, email & url)
Download Free ZXTM Desktop Edition

Recent Articles

Other Resources



www.zeus.com