assign by reference (arrays)?

Jeanne A. E. DeVoto jeanne at runrev.com
Wed Mar 20 08:19:01 EST 2002


At 4:57 AM -0800 3/20/2002, Ben Rubinstein wrote:
>Is there any way to assign by reference?

Calling parameters by reference:
If the name of a parameter variable is preceded with the @ character, that
parameter's value is a variable name, rather than the value in the
variable. Changing the parameter variable in the called handler changes the
value of the variable in the calling handler.

The following handler takes a parameter and simply adds 1 to it:

  on setVariable @incomingVar
    add 1 to incomingVar
  end setVariable

This handler calls the "setVariable" handler above:

  on mouseUp
    put 8 into someVariable
    setVariable someVariable
    answer "someVariable is now:" && someVariable
  end mouseUp

Executing this mouseUp handler displays a dialog box that says
"someVariable is now: 9". This is because, since someVariable was passed by
reference to the setVariable handler, its value was changed when
setVariable added 1 to the corresponding parameter variable.

--
Jeanne A. E. DeVoto ~ jeanne at runrev.com
http://www.runrev.com/
Runtime Revolution Limited - Power to the Developer!





More information about the use-livecode mailing list