use-revolution digest, Vol 1 #1154 - 7 msgs

David Vaughan dvk at dvkconsult.com.au
Wed Feb 26 16:37:07 EST 2003


>
> From: Ben Rubinstein <benr_mc at cogapp.com>
> Date: Thu Feb 27, 2003  00:17:41 Australia/Sydney
> To: <use-revolution at lists.runrev.com>
> Subject: Re: newbies:  beware script locals
> Reply-To: use-revolution at lists.runrev.com
>
>
> on 2/21/03 2:09 PM, Ivers, Doug E wrote
>
>> I love script locals, those local declarations at the top of your 
>> script
>> outside of all handlers:
>>
>> local myLocalVariable
>>
>> [...snip...]
>>
>> I use them a lot in my top level script.  They are great because I 
>> don't have
>> to declare them in each handler and they are "safer" than globals, if 
>> you know
>> what I mean.
>>
>> The caution is that whenever you edit the script, the value of the 
>> local goes
>> away.
>
> Yep - specifically, when the script is recompiled, the values of the 
> locals
> are reset to global.
snip
>     * either make them self healing - eg if the use of the local is to 
> hold
> a calculated value which takes a bit of work to calculate, and is then 
> more
> or less a constant, I have a handler to "ensure they're set",
snip
>     * or, having made sure that the names are unambiguous ... I simply 
> make them global during development.

I personally find this a strange discussion. Firstly, I would rather be 
warning newbies if local variables did *not* lose their value on 
recompilation, and secondly, why write code to emulate some features of 
custom properties when you can use them directly? If you need that 
millisecond of speed by which access to a local is faster than to a 
custom prop then use your startup, preopen or open handler to populate 
the script locals from the custom properties, and save back the values 
at end, to cater for changes. Through use of custom props, script 
locals and ordinary variables, I have been able to relegate globals to 
very rare usage, when you actually want a non-persistent entirely 
global variable. Rev is quite rich in scoping and persistence options.

regards
David
>
>   Ben Rubinstein               |  Email: benr_mc at cogapp.com
>   Cognitive Applications Ltd   |  Phone: +44 (0)1273-821600
>   http://www.cogapp.com        |  Fax  : +44 (0)1273-728866
>




More information about the use-livecode mailing list