function | |||||||||||||
Type | control structure | ||||||||||||
Dictionary | LCS | ||||||||||||
Library | LiveCode Script | ||||||||||||
Syntax |
| ||||||||||||
Summary | Defines a custom function handler. | ||||||||||||
Introduced | 1.0 | ||||||||||||
OS | mac, windows, linux, ios, android, web | ||||||||||||
Platforms | desktop, server, mobile | ||||||||||||
Parameters |
| ||||||||||||
Example |
| ||||||||||||
Values |
| ||||||||||||
Related | Keyword: $, end, private, string Function: functionNames, param, paramCount, result Glossary: call, caller, control structure, execute, expression, handler, message path, parameter, return, statement Control Structure: exit, return | ||||||||||||
Description | Use the function control structure to implement a custom function. Form. The first line of a function handler consists of the word "function" followed by the function's name. If the function has any parameters, their names come after the function name, separated by commas. The last line of a function handler consists of the word "end" followed by the function's name. The purpose of a function is to compute a value and return it to the handler that called the function. The function's value is returned by a return control structure within the function handler. A function handler can contain any set of LiveCode statements. Most functions contain a return statement, which returns the value to the calling handler. This example of a custom function uses two parameters and returns a string :
You create a custom function by writing a function handler for it. When you call the function in a handler, the function call is passed through the message path. When it reaches the object whose script contains the function handler, the statements in the handler are executed. A custom function is called by name, just like a built-in function, as part of an expression. For example, this handler calls the custom function above:
A function can call itself. The following example calls itself to compute the factorial of an integer:
|