Livecode Wiki

@[]

Summary: The character @ (at sign) is used with a parameter declaration, to indicate that a reference to the parameter is passed instead of its value.

Examples:

on setVariable @incomingVar -- notice the @ before the parameter name
 add 1 to incomingVar
end setVariable
on mouseUp
 put 8 into someVariable
 setVariable someVariable
 answer "someVariable is now: " & someVariable
end mouseUp

The character @ is placed before a parameter name to pass a reference to the parameter instead of its value. Pass a parameter reference when you want a handler to change a variable in the calling handler, or when you want a handler to return more than one value.

Passing a parameter by reference means that the data contained in the variable is not duplicated as is the case with normal parameter passing. This is useful in some cases for improving efficiency. Any situation where you are repeatedly passing a large variable to a handler could potentially be speed up by making it a reference parameter. Its important to keep track of which parameters are passed by reference to prevent unexpected behavior.

Parameters to a handler are declared on the first line of the handler. If the name of a parameter is preceded with the @ character, that parameter's value is interpreted as a variable name, rather than the value in the variable. Changing the parameter variable in the called handler changes the value of the variable in the calling handler.

In the above example, the handler setVariable takes a parameter and simply adds 1 to it. Because the parameter for the handler is declared with a leading @, the mouseUp handler passes "someVariable" by reference. This means that when the setVariable handler makes changes to the parameter, it changes the actual variable, and those changes affect all further references in the mouseUp handler to the variable. Executing this mouseUp handler displays a dialog box that says "someVariable is now: 9"

$[]

The character $ (dollar sign) is used to indicate an environment variable on Unix systems and a command-line parameter on Unix or Windows systems.

Examples:

put $LOGNAME into field "Login Name"
if $0 is not myAppName then answer "Problem initializing!"

Use the $ keyword to interact with the system environment and to find out what arguments were used if the application was started up from the command line.

The $ character marks two kinds of special variables: command-line arguments (on OS X, Unix, and Windows systems) and environment variables (on OS X and Unix systems).

If you start up the application from the command line (on OS X, Unix or Windows systems), the command name is stored in the global variable $0 and any arguments passed on the command line are stored in numbered variables starting with the $ character. For example, if you start the application by typing the following shell command:

 myrevapp -h name

then the global variable $0 contains "myrevapp" (the name of the application), $1 contains "-h", and $2 contains "name".

If an argument includes spaces, it must be enclosed in quotes on the command line:

 myrevapp -in "new info.txt"  -out "new info.xml"

On Unix and OS X systems, a variable whose name begins with the $ character is exported to the application's environment, and is inherited by processes started up by the shell function or the open process command. Use this technique to create your own environment variables.

You can access existing environment variables by prepending the $ character to the environment variable's name. For example, the following statement gets the contents of the LOGNAME environment variable:

 get $LOGNAME

&[]

Concatenates two strings. Examples:

put "foo" & "bar" -- evaluates to "foobar"

&&[]

Concatenates two strings and inserts a space between them. It's equivalent to

& space &

Examples

put "foo" && "bar" -- evaluates to "foo bar"

>[]

Compares two values and returns true if the first value is greater than the second value, false otherwise.

Examples:

1 > 0 -- evaluates to true
2 > -15 -- evaluates to true
repeat while counter > 0

>=[]

Compares two values and returns true if the first value is greater than or equal to the second value, false otherwise.

Examples:

put 22 >= 23 -- evaluates to false
if theCount >= 0 then
 go next card
end if

<[]

Compares two values and returns true if the first value is less than the second value, false otherwise.

Examples:

3 < 4 -- evaluates to true
7 < (2 + 1) -- evaluates to false
if thisVariable < 0 then beep

<>[]

Compares two values and returns true if they are not equal, false if they are equal.

Examples

if myVar <> 3 then answer "myvar is not 3"

<=[]

Compares two values and returns true if the first value is less than or equal to the second value, false otherwise.

Examples

if myVar <= 21 then answer "myVar is less or equal to 21"

()[]

Groups operands together. Using parenthesis preserve correct code interpretation.

Examples

if ("a" is within field 1) or ("b" is within field 2) then ...
23 * ((4 / 17) + 60) + (- 7)
put (quantity * priceEach) + shippingCost

*[]

Multiplies two numbers or arrays containing numbers.

Examples

put  3 * 5 -- evaluates to 15
put 1 into tArray[1]
put 2 into tArray[2]
put tArray * 10 into tProductArray 
#now tProductArray[1]=10 and tProductArray[2]=10

+[]

Adds two numbers.

Examples

put 2 + 3 -- returns 5

,[]

Concatenates (joins) two strings and inserts a comma between them. Used with functions and handlers to pass values, you can also put spaces, they will be ignored.

Examples

put "first","second" -- evaluates to "first,second"
myHandler myvar1, myVar2,   myvar3
put myfunction(myvar1, myVar2,   myvar3)

-[]

Subtracts one number from another, or designates a number as negative. You can use it on arrays

put 5 - 3 -- returns 2
put -5 into myVar
put myArray - 3 into myArray2 -- now all elements of myArray 2 are like myArray minus 3


If the first Number or the second Number is an array, each of the array elements must be a number. If a number is subtracted from an array, the number is subtracted from each element. If an array is subtracted from an array, both arrays must have the same number of elements and the same dimension, and each element in one array is subtracted from the corresponding element of the other array.

If an element of an array is empty, the - operator treats its contents as zero.

/[]

Divides one number by another number or one array by another array.

Examples

put 22/7 into approxPi 
put 10 into tNumberArray[1]
put 20 into tNumberArray[2]
put 10 into tDivisorArray[1]
put 5 into tDivisorArray[2]
put tNumberArray / tDivisorArray into tDividedArray
put tDividedArray[1] & comma & tDividedArray[2]
# Yields 1,4

=[]

Compares two values and evaluates to true if they are equal, false if they are not equal. It's equivalent to is.

Examples

if Var1 = Var2 then ...
ABC" = "abc" -- true if and only if caseSensitive is false (standard setting)

When comparing arrays, the = operator first checks if the number of elements in each array is the same, if not the two arrays are different. If the arrays have the same number of elements, they are equal if each element is equal. Specifically this means:

array1 = array2 if (and only if):

the number of elements of array1 = the number of elements of array2 and for each element e in array1, array1[e] = array2[e].

^[]

Use the ^ operator to raise a number to a power, or to find a root of a number.

put 7^3 -- returns 343

\[]

The character \ is used to break a line in a script for display, while still having it treated as a single statement.

Examples:

answer "You've been waiting for"  numberOfMinutes & \
"minutes." with "Keep Waiting" or "Cancel"

If a line is too long to fit conveniently in the script window, use the \ character to break it into two (or more) lines for viewing.

A line that is split with \ is shown in the script editor as more than one line, but when it's executed, it is treated as a single line of code.

The script editor automatically indents continued lines, as shown in the example above. A \ character which is used within a literal string does not break the line, because the \ is treated as part of the quoted string instead of being treated as a line continuation. For example, the following statement causes a compile error because the \ character is inside the quotes:

 answer "This is a test. This is only a test. \
Had this been an actual life..." with "OK" -- BAD EXAMPLE

The above bad example can be corrected by using the operator to break up the long string:

 answer "This is a test. This is only a test." \
 "Had this been an actual life..." with "OK" -- good example

The string has been broken into two substrings, so the \ character is no longer within a literal string. This second example does not cause an error.