![]() |
|
? |
Longname: | ? | ![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
Released: | 1.00 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Created: | 1.00 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Last modified: | 7.51c | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
See also: | addstr defstr { } : 3B2 Scripting Expressions (n/a) |
Summary |
3B2's script extension has a condition tester that allows macros to be executed only when the condition is true. As with labels and jumps the condition tester, in this form, is only available within scripts executed with trun. Examples of all 'conditions' and their operators are documented below. |
Example extract |
|
Syntax
|
condition:n |
|
element2: |
In addition to the same values as element1, element2 can also take various test options listed below, specify the test range and the option:
The macro you want to run if condition is true. This can either be a normal 3B2 macro or, uniquely, a { or } macro to jump to a certain section of your script. If the macro contains any variables that need replacing with a value (by terminating the line with a ^) the replacement does not take place until the macro portion of the line is passed to the normal macro processor. (This means that the variable(s) which make up part of the test at the beginning of the line do not get replaced.) |
Examples of various conditional tests are detailed below. |
Example |
If ^var1 is equal to ^var2, jump to label.
If ^var1 is greater than 1, go to page 100
If ^var1 is less than total of ^page plus ^count jump to label (see Expressions_en
If ^char is equal to the Keycode of 'a' then insert text
If ^value is -1 then insert text |
Example |
Another commonly needed requirement is to test whether a string is empty (contains no characters at all). You can do this by comparing it with a blank string represented by " ":
|
Example |
It can also be necessary to check whether or not a number is odd or even. Because numeric variables are always whole numbers, dividing the number you want to test by two, and then multiplying it by two, will produce different results according to whether the number was odd or even. In the example below we find out if the last page of a document is even or odd:
|
Example |
Verify strings let you test a string for certain criteria, and return a result of true or false, depending on whether the string matched the given criteria or not, see the test option parameter. This example of the 'i' option tests if the variable ^num contains an integer number in the range 1 to 20 and if so display to the screen.
|
Example |
Regular expressions add a powerful extension to the conditional test macro see also Regular expressions_en. The examples below illustrate some of the many options available using regular expressions.
|
Example |
Execute macro if test not true. In this case we are testing if the ^text variable contains something other than a tag who's name consists of characters a-z.
|
Example |
As shown in the example below the 'wild card' enables you to test for data without exact comparison being known, as '?' in search and replace.
|
Example |
Enables 'case sensitive' tests on strings. The example below will not execute the macro, as a capital 'A' will have a higher value than the lower case 'a'.
If ^var1 is equal to ^var2 then jump to label |
Document created on 08-Feb-2003 (revision 1)