• 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: bug or feature?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug or feature?


  • Subject: Re: bug or feature?
  • From: JJ <email@hidden>
  • Date: Thu, 18 Oct 2001 20:26:56 +0200

> I was under the impression that global variables were not persistent from
> run to run, only properties were. I was surprised to discover that global
> variables seem in fact to also be persistent. You can see this by running
> the following as an applet (Classic or OS X).

A global is an undefined property. That's the reason because you get an
error on your first run.
In your script, you aren't storing a value only by declaring "x" as a
global. But, to define a property, you must do it.

i.e.
::::::::::::::::::::::::::::
global x

try
set x to (y * z)
on error
set y to 4
set z to 3
end try
::::::::::::::::::::::::::::

-- first run returns (y,z) = (4,3)
-- seconds run returns x = 12
You've stored two variables into a global

Now:
::::::::::::::::::::::::::::
property x : (y * z)
::::::::::::::::::::::::::::

-- it doesn't compile > "y" undefined

::::::::::::::::::::::::::::
property y : 4
property z : 3
property x : (y * z)
::::::::::::::::::::::::::::
-- Compiles
-- Silly, no? But look at this:

::::::::::::::::::::::::::::
global x

try
set x to (y * z)
on error
set y to 4
set z to 3
end try

try
set z to (x * y)
on error
end try
::::::::::::::::::::::::::::
-- first run returns (y,z) = (4,3)
-- second run returns z = 48 -- was (x*y)= (4*3)*4
-- third run returns z = 768!!! -- was (x*y). See below:
x = y * z > x=4*48 > 192
z = x * y > z=192*4 > 768

So, we've created a live property.

But, in this second example:

::::::::::::::::::::::::::::
property y : 4
property z : 3
property x : (y * z)

set z to (x * y)
::::::::::::::::::::::::::::

-- z always is 48

I'm mathematical overload!

JJ
> -------------------------------------------------------------------------
> global x
>
> try
> class of x
> display dialog (("Class of x is " & class of x as string) & return & ,
> "Value of x is: " & x as string) & return & "No error"
> on error
> set x to "This is a test."
> display dialog (("Class of x is " & class of x as string) & return & ,
> "Value of x is: " & x as string) & return & "In error block"
> end try
> -------------------------------------------------------------------------
>
> First run result:
>
> display dialog "Class of x is string
> Value of x is: This is a test.
> In error block"
>
> Second run result:
>
> display dialog "Class of x is string
> Value of x is: This is a test.
> No error"


  • Prev by Date: Re: hash arrays and other mysteries
  • Next by Date: Re: AppleScript Suite
  • Previous by thread: Re: bug or feature?
  • Next by thread: Script launcher
  • Index(es):
    • Date
    • Thread