• 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: global variables
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: global variables


  • Subject: Re: global variables
  • From: Luther Fuller <email@hidden>
  • Date: Wed, 17 Jul 2013 16:44:49 -0500

On Jul 17, 2013, at 3:27 PM, Kaydell Leavitt wrote:

global x
set x to 2
set x to x + 1
display dialog "x: " & x

It always displays 3 as the result.

Yes. You must save a script as an application (bundle) to see the persistence.
Save this as an application …

-- If you run this from the editor, it always displays "x = 0".
-- This script must be compiled as an application (bundle).

on run
-- global x
my increment()
display dialog "x = " & x
end run

on increment()
global x
try
set x to (x + 1)
on error
set x to 0
end try
end increment

Every time you launch the application it will display the incremented value of the previous launch.
('global x' is not required in the run handler.)




 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >global variables (From: Jim Brandt <email@hidden>)
 >Re: global variables (From: Luther Fuller <email@hidden>)
 >Re: global variables (From: Kaydell Leavitt <email@hidden>)

  • Prev by Date: Re: Revisited: controlling sound input on Mac Pro?
  • Next by Date: Re: global variables
  • Previous by thread: Re: global variables
  • Next by thread: Re: global variables
  • Index(es):
    • Date
    • Thread