initialize an static, local, script-wide variable to empty
monte at sweattechnologies.com
Fri Apr 11 22:07:02 CDT 2003
> > As far as I know, you can't initialize
> > variables outside a handler.
This is not correct. You can initialize locals outsite the handler. For some
reason you can't initialize globals. Perhaps that's a bug? It's probably not
because if you had two scripts initializing a global to different things
then what would you do? You can only initialize a variable once.
> 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.
If you want to reset every time your main handler executes then you don't
want a local variable in the object scope. You sould just use parameters for
this kind of thing.
> 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?
No. It's all about variable scope. A local declared within a handler has
only handler scope. A local declared outsite the handler has object scope
(all handlers in the object can access the variable). A global declared
within a handler has only a handler scope within the object but can be
declared and used in other handlers/objects. A global declared outsite the
handler has object scope.
To write good/maintanable code you should try to take advantage of variable
scope while designing your scripts to use the minimum possible. The wider
your variable scope the harder it is to see where the variable gets changed.
More information about the use-livecode