Re: Idle Help
Re: Idle Help
- Subject: Re: Idle Help
- From: Chris Nebel <email@hidden>
- Date: Wed, 06 Dec 2000 12:22:32 -0800
- Organization: Apple Computer, Inc.
Byron Peterson wrote:
>
How do I pass variables from the 'run' section to the 'idle' section
>
without using 'global' or 'property' statements.
>
>
ie.
>
>
on run
>
set test to "Hello World!"
>
end run
>
>
on idle
>
display dialog test
>
return 10
>
end idle
You don't. I realize that you may have had "Globals Are Bad" burned
into your brain in an introductory programming course, but the reality
is that sometimes there's no other way. This is one of those times.
The difficulty is that "run" and "idle" are independent entry points
into your script that are called from the outside, i.e., the applet
shell. In order to share information between them, you have to put it
somewhere both handlers can see, and that means a global or property of
some sort.
If it really bothers you, you can compartmentalize the offending globals
by putting them inside a script object, like this:
script messages
property hello : ""
end script
on run
set hello of messages to "Hello world!"
end
on idle
display dialog hello of messages
end
If there's only one global, this technique is mostly a waste of time,
but if you have lots, and they fall into clear groups, then it's a good
way to keep them separate.
--Chris Nebel
AppleScript Engineering
References: | |
| >Idle Help (From: Byron Peterson <email@hidden>) |