Functions are like messages. Functions and handlers have a lot in common, they both do stuff, but a Function also returns a value. There are many built-in functions in LiveCode and you can write your own custom function, such as the following:

Custom function syntax is:

function MyFunc param1                   -- MyFunc has one parameter, which it 
 return param1 + 1                       -- adds one to, then returns that value
end MyFunc                               -- to the calling statement.

It is used this way

on MouseUp                         -- MyFunc is called as part of a regular LiveCode
 answer MyFunc(4)                  -- statement. The parameters in the calling
end MouseUp                        -- statement must be inside parenthesis.

An other example.

function Fred george, bob, dude          -- Fred has three parameters, two of which
  put george + bob - dude into Temp      -- are added and the third subtracted. Then
  return Temp                            -- the value is returned to the calling
end Fred                                 -- statement.

And now the calling statement.

on mouseUp                               -- george = 4, bob = 5 and dude = 6.
  put Fred(4,5,6) into Susan             -- Fred and Susan = 3.
end mouseUp

Be sure to put parenthesis around the parameters in the calling statement. But do not use additional parenthesis. If you do, these are evaluated as a single parameter. For example:

put ReturnContact((Bill,Howard),Phoenix) into tName

function ReturnContact firstName,LastName,address
 return firstName
end ReturnContact

ReturnContact only gets two parameters, firstName = Bill,Howard and LastName = Phoenix. firstName is returned, so tName = Bill,Howard because these are evaluated as param 1 due to the parentheses.

Here is a list of common LiveCode built-in functions: (pleas help us to complete this list)

Community content is available under CC-BY-SA unless otherwise noted.