Using Director > Writing Scripts with Lingo > Using handlers > Using arguments to pass values to a handler |  |

Using arguments to pass values to a handler

By using arguments for values, you can give the handler exactly the values that it needs to use at a specific time, regardless of where or when you call the handler in the movie. Arguments can be optional or required, depending on the situation.

To create arguments for a handler:

Put the arguments after the handler name. Use commas to separate multiple arguments.

For example, the following handler, called `addThem`, adds two values it receives in the arguments `a` and `b`, stores the result in local variable `c`, and uses the Lingo term `return` to send the result back to the original handler:

    on addThem a, b
    	-- a and b are argument placeholders
    	c = a + b
    	return c
    end

When you call a handler, you must provide specific values for the arguments that the handler uses. You can use any type of value, such as a number, a variable that has a value assigned, or a string of characters. Values in the calling statement must be in the order they follow in the handler's arguments, and they must be surrounded by parentheses.

The following statement is a calling statement for the `on addThem` handler:

    set mySum = addThem(4, 8)

Because `4` is first in the list of arguments, Lingo substitutes it for `a` in the handler. Likewise, because `8` is second in the list of arguments, Lingo substitutes `8` for `b` everywhere in the handler.

After the calling statement sends these parameters to the handler, the handler returns the value `12`, which corresponds to the variable `c` inside the `on addThem` handler. The variable `mySum` in the calling statement is then set to `12`.

You can also use expressions as values. For example, the following statement substitutes `3+6` for `a` and `8>2` (or `1`, representing `TRUE`) for `b`, and would return `10`:

    set mySum = addThem(3+6, 8>2)