Don't understand the meaning of "local"
Dennis Brown
see3d at writeme.com
Thu Dec 22 16:39:29 EST 2005
Jim,
Local variables are only valid during the handler execution that they
are local to. The values are not saved once the handler is exited --
they cease to exist.
Script local variable values are saved --like a global for only this
script.
Dennis
On Dec 22, 2005, at 3:58 PM, Jim Hurley wrote:
> I suspect that this issue has been dealt with before, but I don't
> get it. I thought I understood what a local variable was.
>
> Create a field. Put a bunch of returns into it--or several lines
> of text.
>
> Lock the field and put the following script into it.
>
> Hold the mouse down and move it through the field. I would have
> expected a list of the lines that have been moved over to appear in
> the msg box. Instead only the current line is shown.
>
> But I so get the entire list if I include tLines as a local script
> variable. Apparently tLines is set to empty after every execution
> of mouseMove, unless tLines is included as a local script variable.
>
> I get the feeling that mouseMove stops and restarts with every
> cycle and therefore forgets the value of tLines.
>
> However if tLines is set as a local script varable then the script
> continues to run and therefore remembers tLines.
>
> I had thought that the function of the local script declaration was
> to allow the variable to be used throughout the handlers of the
> script. However, in this example tLines is used only in mouseMove.
>
> I think I ran into this behavior earlier when adding a rolling
> snowball asynchronously to Scott's snow storm. I wondered why local
> variables were kept in memory each time a handler called itself
> after a few milliseconds. Once again it appears that setting a
> local script variable retains the variables in memory--even when
> the script stops (?) until called again.
>
> Anyone understand the different behavior of this script depending
> on whether tLines is declared as a local script variable? Or, more
> challenging, can anyone explain it to me?
>
>
> local myName, --tLines
>
> on mouseDown
> put the name of me into myName
> end mouseDown
>
> on mouseUP
> put "" into myName
> end mouseUP
>
>
> on mouseMove
> if myName is "" then exit mouseMove
>
> put word 2 of the MouseLine into tLine
> if tLine is not in tLines then put tLine & comma after tLines
> put tLines into msg box
>
> end mouseMove
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
More information about the use-livecode
mailing list