Re: Compact Handlers Togo!
Re: Compact Handlers Togo!
- Subject: Re: Compact Handlers Togo!
- From: email@hidden
- Date: Thu, 16 Aug 2001 15:30:11 EDT
Togo - moving to West Africa?
I think you are confused about scope. Properties and globals are elements of
scripts (and script objects), not handlers. The whole point of "global" is
that it is global for a script, not restricted to a handler (handlers use
local variables). If you want a "portable" object with properties and
globals, you want a script object.
script john
global gVariable
on compactHandler()
try
--This will check to see if the global variable has a value
gVariable
--Increase the variable's value to show its value stays between
runs
set gVariable to gVariable + 1
on error
--First Initilizing of the variable
set gVariable to 1
end try
end compactHandler
end script
tell john
try
gVariable
--After Initializing of the variable we can see it
--increase in value everytime we run the script
activate me
display dialog gVariable
on error errmsg
--On first run the global variable isn't initialized
activate me
display dialog errmsg
end try
--Call the handler which will initialize the global variable
compactHandler()
end tell
I personally don't like using properties for values that need to persist. I
read and write my data from and to text files instead. This has several
advantages:
1) They can be manually reviewed and edited
2) They persist even when the script is edited
3) They can be shared more easily among multiple scripts.
Jeff Baumann
email@hidden
www.linkedresources.com
In a message dated 8/15/01 5:58:58 PM, Jason Bourque wrote:
>
Hello everyone,
>
>
I have been thinking that the handlers I create aren't that portable. i.e.
>
Copy the handler. Any properties or globals associated with the handler must
>
be copied to the top of the script
>
>
So, I thought including the Properties and Globals in the actual handler
>
would make it much more portable.
>
>
First to treat globals like properties and have the last value of global
>
keep after a run.
>
>
Below is the script that demonstrates what I have accomplished, but I am
>
looking for comments about it. i.e. If it is useful and am I understanding
>
the logic correctly, general comments.
>
>
Please post all responses to the list, for I am in two locations with
>
different email.
>
>
Thanks,
>
>
--Save the following code as an applet and run a few times to see the
>
persistance of the global.
>
>
on compactHandler()
>
>
global gVariable
>
>
try
>
--This will check to see if the global variable has a value
>
gVariable
>
>
--Increase the variable's value to show it's value stays between
>
runs
>
set gVariable to gVariable + 1
>
on error
>
>
--First Initilizing of the variable
>
set gVariable to 1
>
end try
>
>
end compactHandler
>
>
>
try
>
gVariable
>
>
--After Initializing of the variable we can see it
>
--increase in value everytime we run the script
>
activate me
>
display dialog gVariable
>
>
on error errMsg
>
>
--On first run the global variable isn't initialized
>
activate me
>
display dialog errMsg
>
>
end try
>
>
--Call the handler which will initialize the global variable
>
my compactHandler()
>
>
Jason Bourque
>
Senior Script Developer
>
Publishing Automation
>
MFS Investment Management
>
617-954-5312