Re: global declarations for many variables: is there a better way?
Re: global declarations for many variables: is there a better way?
- Subject: Re: global declarations for many variables: is there a better way?
- From: Sander Tekelenburg <email@hidden>
- Date: Thu, 5 Apr 2001 17:55:55 +0200
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
At 10:44 -0400 UTC, on 05/04/2001, Chris Adams wrote:
>
I am stuck in a way that works, but I think that there must be a better
>
way.
>
>
I have variables that I would like to make reference to in a number of
>
routines within a script. What works for me is to declare the variables at
>
the beginning:
>
>
property height:100
>
property width:200
>
>
global numberOfPictures
>
global aspectRatio
>
global fileName
>
global caption
>
etc.
Just concerning notation, you can write that as:
global numberOfPictures, aspectRatio, fileName, caption.
>
This works for me. I feel that somehow I should figure out ways to program
>
so that I do not need so many global variables
You can carry variables along to handlers when needed:
set myVariable to {"a", "b", "c"}
someHandler(myVariable)
set myVariable to {"1", "2", "3"}
otherHandler(myVariable)
on someHandler(myVariable)
set anotherVariable to item 1 of myVariable
end someHandler
on otherHandler(myVariable)
set anotherVariable to item 1 of myVariable
end otherHandler
This way you don't need to declare them as global when they're only used in a
few places.
Hope this helps a bit. There's far more to say about it, but currently this
is the extent to which I feel comfortable with the issue :)
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <
http://www.pgp.com>
iQA/AwUBOsyVZOsywKfXgqKdEQIXEgCffmhc6j8NYfHXNI6AxCIaY4Rfqo4An0gK
Glo5Umn6HyL5RQA/dOmnWURd
=FWQP
-----END PGP SIGNATURE-----
--
Sander Tekelenburg, <
mailto:email@hidden>
Web site at <
http://www.euronet.nl/~tekelenb/>
Mac user: "Macs only have 40 viruses, tops!"
PC user: "SEE! Not even the virus writers support Macs!"