send

Sends a message to an object.

# Metadata

Platforms: desktop, server, mobile OS: mac, windows, linux, ios, android Introduced: 1.0 Security:

# Syntax

send [script] message [ to object [in time [{seconds | ticks | milliseconds}] ] ]

# Params

- message : An expression that evaluates to a message name, possibly including parameters. - object : Any object reference. If you don't specify an object, the message is set to the object whose handler contains the send command. If you specify a time, you must also specify an object. - time : If you don't specify a unit of time, the default of ticks is used.

# Examples

send "mouseDown" to button "next"

send "mouseDown" to button "text" of stack "project2"

# A simple timer using send example local sTime on mouseUp put 0 into sTime send "timerIncrement" to me in 1 seconds end mouseUp on timerIncrement add 1 to sTime put sTime send "timerIncrement" to me in 1 seconds end timerIncrement

send script "answer the short name of me" to stack "Message Box"

# Description

Use the send command to override the normal message path, or to delay a command until a specified time.

The message can be either the name of a handler or a LiveCode statement. If the message is a literal string containing more than one word (for example, if it includes parameters, or if it is a multi-word command), it must be enclosed in double quotes.

If the `script` form is used, the message is simply sent unmodified to the object. Otherwise, any parameters are evaluated before they are passed to the send command. For example, suppose there is a stack named "Stack" with script

on doAnswer pParam answer pParam end doAnswer

function myName return the short name of me end myName

and a button on the stack named "Button" with script

on mouseUp send "doAnswer myName()" to this stack send script "doAnswer myName()" to this stack end mouseUp

function myName return the short name of me end myName

clicking the button would result in an answer dialog first saying "Button" as the `myName` function would be evaluated in the button context, then "Stack" as using the `script` form would result in the `myName` function being evaluated in the stack context.

When the send command is used the stack containing the target handler temporarily becomes the defaultStack. All object references in the message are evaluate in the current context i. e. the defaultStack. Therefore references within the message that refer to "this card" or "this stack" will be referring to the card or stack where the target handler is located.

It is a parse error to specify a time when using the `script` form.

>*Important:* Specifying a time can affect the order in which > statements are execute. If you don't specify a > time, the message is sent immediately, and any handler it > triggers is completed before the rest of the current > handler is execute. If you use the send in time form of > the send command --even if you specify a time of zero > seconds--the current handler finishes execute before the > message is sent.

>*Note:* Using the send command is slower than directly > execute the commands using the normal > message path. For best efficiency, use the send command only when > you want to delay the message or when the handler you want to > execute is not in the message path.

# Tags

# See

- **property:** callbacks, backgroundBehavior - **message:** mouseUp - **keyword:** word - **control structure:** function - **function:** result, pendingMessages - **command:** debugDo, dispatch, call, cancel - **glossary:** object, literal string, return, evaluate, execute, command, LiveCode, double quote, trigger, message path, message, parameter, statement, handler