Lingo Dictionary > O-R > return (keyword)

 

return (keyword)

Syntax

return expression

Description

Keyword; returns the value of expression and exits from the handler. The expression argument can be any Lingo value.

When calling a handler that serves as a user-defined function and has a return value, you must use parentheses around the argument lists, even if there are no arguments, as in the diceRoll function handler discussed under the entry for the result function.

The function of the return keyword is similar to that of the exit command, except that return also returns a value to whatever called the handler. The return command in a handler immediately exits from that handler, but it can return a value to the Lingo that called it.

The use of return in object-oriented scripting can be difficult to understand. It's easier to start by using return to create functions and exit handlers. Later, you will see that the return me line in an on new handler gives you a way to pass back a reference to an object that was created so it can be assigned to a variable name.

The return keyword isn't the same as the character constant RETURN, which indicates a carriage return. The function depends on the context.

To retrieve a returned value, use parentheses after the handler name in the calling statement to indicate that the named handler is a function.

To see an example of return (keyword) used in a completed movie, see the Parent Scripts movie in the Learning\Lingo Examples folder inside the Director application folder.

Example

This handler returns a random multiple of 5 between 5 and 100:

on getRandomScore
	theScore = 5 * random(20)
	return theScore
end getRandomScore

Call this handler with a statement similar to the following:

set thisScore to GetRandomScore()

In this example, the variable thisScore is assigned the return value from the function GetRandomScore. A parent script performs the same function: by returning the object reference, the variable name in the calling code provides a handle for subsequent references to that object.

See also

result, RETURN (constant)