alex at tweedly.net
Sun Feb 6 05:53:54 CST 2005
Scott Rossi wrote:
>I'm looking for a way to employ concise persistent variable names in a
>Currently, I'm using the form:
> get the hilite of buttonPlay
>...where buttonPlay is a script local variable containing the absolute
>reference to a control. The problem is, as soon as I edit the script, the
>value of buttonPlay is lost. I have about 15 of these references to manage.
>If I change the variables to globals, the values will be persistent, but
>I'll have to declare the global names everywhere in the script, which is
>going to be a major chore in a 1700+ line script that has around 70
>handlers, not all of which require the globals.
Is this one large 1700 line script, with many handlers within it ?
Or is it a total of 1700 lines, spread over many scripts ?
If it's the former : can't you simply declare them as global at the head
of the script ? (OK, it makes the variable be in scope within the
handlers that don't need them - but good practice says you wouldn't be
re-using those name anyway, so it's safe).
If the latter: Can you do something like
repeat with i = 1 to the number of controls in stack "whatever"
put the script of control i into tScript
replace "local buttonPlay" with "global buttonPlay"
set the script of control i to tScript
(Hopefully the local declarations follow some pattern or consistency
that would let you do this)
>If I change the variables to custom properties, I'll have to use a form
> get the hilite of (the buttonPlay of me)
>Having to include the owner of the property makes for a fair amount of extra
>script and complicates the readability of the script in places, compared to
>the simple "buttonPlay".
How widely are these variables being modified ?
If that happens only in VERY few places, you could possibly you move
them to custom properties, but on entry to most of the handlers, copy
the values from custom properties to the current local variables.
put (the cButtonPlay of me) into buttonPlay
get the hilite of buttonPlay
and in other places
-- can't use local buttonPlay because it is modified in this handler
get the hilite of (the cbuttonPlay of me)
set (the cButtonPlay of me) to ...
>So, my question is, might there be some way I can make my short object
>references persistent, or must I use a more verbose form to do this?
>I've considered turning the variables into functions, like buttonPlay(), but
>it seems inefficient to have continually rebuild an object reference that
>could be defined once and stored. But then I'm back to the original
>It's late here and I'm out of ideas so I'm looking for suggestions on how I
>might solve this dilemma.
By the time you read this, it'll probably be early for you - and with
luck you'll come up with something better ...
Alex Tweedly http://www.tweedly.net
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.5 - Release Date: 03/02/2005
More information about the use-livecode