Overview | Commands | Syntax | Properties | Functions | Event Handlers | Compatibility
Here are the operators that can be used.
2 * 3
2 / 3
2 ^ 3
raise to the third power
7 div 5
7 mod 5
2 > 3
2 < 3
2 >= 3
greater than or equal to
2 <= 3
less than or equal to
2 == 3
2 != 3
not equal to
"abc" is "def"
"abc" is not "def"
not equal to
"abc" is in "123abcdef"
does string contain another string
"abc" is not in "123abcdef"
string is not in another string
2 + 3
2 - 3
&& combine two strings (concatenation).
put "a" & "b" into x answer x -- displays "ab" put "a" && "b" into x answer x -- displays "a b"
You can also use
a = b, which is equivalent to
a == b
The constants 'true' and 'false' are used often. Internally there is no distinct boolean type, but the strings "true" and "false" are interpreted as true and false respectively.
true and false
true or false
Logical operations are not guaranteed to be short-circuiting. In other words,
put (true or myfunction()) into x
still will call
myfunction, when it hypothetically could have been skipped.
The following constants are defined:
pi newline tab empty quote one two three four five six seven eight nine ten colon comma true false up down space return cr formfeed linefeed
Declares that a variable is a global.
1) it can be accessed from any other script
2) the contents are saved even after the function is complete.
The contents are lost when the stack is exited, however, and are not saved to disk or as part of the stack.
global currentData1, currentData2 put "stored 1" into currentData1 put "stored 2" into currentData2
Use to run certain code based on a condition that can be true or false.
In the example
put 2 into x if x > 0 then answer "x is greater than 0" end if
First, we'll check the expression
x > 0. Since it evaluates to true, the code inside is run.
You can also include an "else" section that will be run only if the expression evaluated to false.
if x > 0 then answer "x is greater than 0" else answer "x is not greater than 0" end if
You can chain together many different conditions with "else if".
put 3 into x if x > 3 then answer "x is greater than 3" else if x < 3 then answer "x is less than 3" else if x is 3 then answer "x is 3" end if
As soon as one of the branches is taken, all of the remaining branches are skipped -- even if the condition is true.
if 3+3 is 6 then answer "aaa" else if 2+2 is 4 then -- this not run, even though the expression is true answer "bbb" end if
if 3+3 is 6 then answer "it is" -- you can even do this if 3+3 is 7 then answer "it is not" else answer "it is"
Exit the current loop. Equivalent to "break" in C.
repeat with x = 1 to 3 if x == 2 then exit repeat end if answer x end repeat -- displays 1 -- and does not display 2 or 3
Skips to the end of the current handler, skipping over all subsequent lines of code. Similar to return, but does not point to a value.
on mouseUp put cd fld "fld1" into x if x is not a number then answer "you did not type a number" exit mouseUp answer "this will never get called" end if put x * 2 into cd fld "fld1" end mouseUp
exit to ViperCard
Exits the current handler and passes the message up to ViperCard. Typically, this stops code execution completely.
exit to HyperCard is also accepted.
exit to ViperCard can also be useful if you have overridden a default message and want to defer to the default behavior.
on myHandler exit to ViperCard answer "this will never get called" end myHandler on mouseUp myHandler answer "and even this will never get called" end mouseUp
Inside a loop, go back to the top of the loop, skipping the next line(s) of code. Equivalent to "continue" in C.
repeat with x = 1 to 3 if x == 2 then next repeat end if answer x end repeat -- displays 1 -- displays 3 -- and does not display 2
Exits the current function and calls a function higher in the message hierarchy. For example, if a button has the script
on mouseUp answer "button handling the event" end mouseUp -- and the current card has the script on mouseUp answer "card handling the event" end mouseUp
and the button is clicked, only the button's code will be run.
If you want both to be run, you can use the pass command. If a button has the script
on mouseUp answer "button handling the event" pass mouseUp -- any code here will be skipped end mouseUp --and the current card has the script on mouseUp answer "card handling the event" end mouseUp
and the button is clicked,
both will be run.
Use to create a loop.
repeat with x = 1 to 5 answer "x is now" & x end repeat repeat with x = 5 down to 1 answer "x is now" & x end repeat repeat 3 times answer "hi" end repeat repeat forever answer "this is an infinite loop" end repeat put 0 into counter repeat forever answer "but not this" add 1 to counter if counter > 3 then exit repeat end if end repeat put 0 into counter repeat until counter > 3 add 1 to counter end repeat put 0 into counter repeat while counter <= 3 add 1 to counter end repeat
Returns a value from the current function.
Note: no lines of code after the return statement will be run.
function myAddition p1, p2 return p1 + p2 answer "this line will never be reached" end myAddition on mouseUp put myAddition(1,2) into x end mouseUp