initialize an static, local, script-wide variable to empty
ambassador at fourthworld.com
Fri Apr 11 19:11:00 CDT 2003
erik hansen wrote:
> the TD says:
> local A=1,B=2,C=3
> # creates variables with initial values
> you are right, this does not work when the local
> command is outside a handler. nor are the values
> held when all of the handlers finish.
> sHolder = empty, the reset i wanted.
> just determined by the good old empirical method.
What was the emprical method used?
The situatioon with script-local vars is like Schroedinger's Cat*, a
needlessly complicated metaphor for "the act of observing disturbs the
Declared variables are initialized when a script loads, but once the script
has loaded all other actions on that variable need to happen inside of
This bit about loading scripts is useful to keep in mind when debugging:
any script-local variable will be re-initialized whenever you save or apply
With a slightly limited range of expression types (constants only, no
functions), you can initialize a script-local variable outside of a handler
in its declaration, as your example shows.
You should be able to display its value at runtime in the Message Box or an
Answer dialog, but if you edit the script just keep in mind that it will be
> is it close to say that the script/static global
> performs as a parameter-passer while saving you
> the bother of cluttering up your script?
There's a certain Zen of Script-Local Variables that I've begun to sense in
my own work but have not been able to articulate. But they've changed my
whole coding style.
I tend to use them in two circumstances:
- where I might have used globals but want to avoid name-space collisions
(great for utilities and plugins where you have no control over the name
- when passing data to handlers, as you suggest, where the same container is
used among many handlers (except those that require their own copy or alter
it ways that would be undesireable elsewhere).
Fourth World Media Corporation
Developer of WebMerge 2.2: Publish any database on any site
Ambassador at FourthWorld.com http://www.FourthWorld.com
Tel: 323-225-3717 AIM: FourthWorldInc
* Cecil Adams' take on Scroedinger's Cat is a kick:
More information about the use-livecode