From: Ben Rubinstein <[EMAIL PROTECTED]> Date: Thu Feb 27, 2003 00:17:41 Australia/Sydney To: <[EMAIL PROTECTED]> Subject: Re: newbies: beware script locals Reply-To: [EMAIL PROTECTED]


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: [EMAIL PROTECTED] Cognitive Applications Ltd | Phone: +44 (0)1273-821600 http://www.cogapp.com | Fax : +44 (0)1273-728866


_______________________________________________ use-revolution mailing list [EMAIL PROTECTED] http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to