|
SurferScript Expressions
ScreenSurfer expressions provide you with the ability to manipulate text and numeric values. For example, you can add two integer variables together to produce a sum for display to the user. There are three types of expressions in ScreenSurfer:
- Text Expressions
- Integer Expressions
- Floating-point Expressions
The type of an expression is a function of the expression's context and contents. For example, the following tag will produce the result "234" instead of "9":
<TESHOW 2+"3"+4>
How is this so? The reason is that all values in ScreenSurfer are polymorphic, which means that regardless of the type of a value (whether a literal or a variable) it can always provide a text string, integer or floating point value. This provides efficiency in the storage of variables combined with freedom in their use (you don't have to worry about conversion from one type to another).
Ambiguous situations occur when the expression has a mix of types, such as the integer and text literals in the prior example. In this case, the type of the expression will be based on the most complex value in the expression, climbing from most simple (integer) to next (float) to most complex (text). In other words, if you have three integer values and one float, you will have a floating-point expression; if you have three integers and one text value, you will have a text expression.
Math Precedence
SurferScript expressions support standard math precedence for the four allowed operators add ("+"), subtract ("-"), multiply ("*") and divide ("/"). When you mix these operators in any expression, the natural order of precedence will be enforced by ScreenSurfer, whereby multiply and divide operations will be performed prior to add and subtract operations. For example, 2+3*4 will result in a value of 14.
You can enforce any order of precedence in your expressions by using parenthesis to group values and ensure a specific result. For example, (2+3)*4 will result in a value of 20.
Text Expressions
A text expression as a formula in a <TESET or in any situation where a tag expects a text value consists primarily of a text literal value (or any variable) optionally concatenated with one or more additional text values. The concatenation of text values is achieved with the plus (+) symbol. Note that there is a variety of text manipulation functions documented in the SurferScript Reference, including TextLeft("source", length), TextRight("source",length) and TextMid("source",start,length).
Here are some examples:
<TEACTION ENTER web.input+"[erase eof][enter]">
<TEACTION ENTER "AU "+SearchWords+"[enter]">
<TESET screen_text1 = TextMid(screen_text,3,1)>
|