• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Idle Help
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Idle Help
      • From: Byron Peterson <email@hidden>
    • Re: Idle Help
      • From: Phi Sanders <email@hidden>
References: 
 >Idle Help (From: Byron Peterson <email@hidden>)

  • Prev by Date: Re: Problem scripting Acrobat
  • Next by Date: Round Handler, care to share.
  • Previous by thread: Re: Idle Help
  • Next by thread: Re: Idle Help
  • Index(es):
    • Date
    • Thread