• 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: KOENIG Yvan <email@hidden>
  • Date: Thu, 8 Mar 2007 17:36:28 +0100


Le 8 mars 07 à 17:02:20, Larry the O a écrit :

OK, I must be misunderstanding something really basic here.

All I'm trying to do is create a droplet that starts out by declaring and initializing a bunch of global variables, then runs a series of subroutine calls to do the work. The idea of using the global variables is so that the subroutines can read and write the global variables without them having to be explicitly passed in the subroutine call, right?

Not working. It worked when I was writing the code and running it directly from the script window, but once I added the droplet front end (which was independently tested and seems to work fine), the global variables are no longer working.

The actual code is kind of messy right now, so, for the moment, makePretend code:

on open

global littleMess
global bigMess
global ohMiGod

set littleMess to {}
set bigMess to ""
set ohMiGod to "toilet paper"

bumpAndGrind()
twistAndShout()
shakeAndBake()

end open
--

on bumpAndGrind()

set littleMess to {"incontinent dog", "naughty cat"}
display dialog "Pivot and spin"
end bumpAndGrind
--
on twistAndShout()

if bigMess is "" then
set bigMess to "Uncle Ben's Rice"
end if
end twistAndShout
--

on shakeAndBake()
if ohMiGod is "toilet paper" then
set bigMess to "You don't want to know."
else
set littleMess to {"cleanup effort", "disaster recovery"}
end shakeAndBake



----------------------

Now, shouldn't that work, that is, shouldn't the subroutines be able to read and write the global variables? But it's not. Instead, I'm having to pass each global variable in the call and explicitly return the changed variable at the end of the routine.

Is the problem that the subroutines should all be inside the open statement?

Thanks!

larry the o


From my point of view, your code met two problems.

- 1 - It is written as a droplet so, it is executed only if you drag and drop an icon on it's own one.

- 2 - You defined thre globals in a handler so they are not seen by other handlers.
If you define the global just before the "on open" instruction, the code will work.


If you want to use it as an applet (double-click it), remove the on open and end open instructions.
For my own use, I don't code globals but properties.


Yvan KOENIG

_______________________________________________
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: Larry the O <email@hidden>)

  • Prev by Date: Re: Global variables
  • Next by Date: Re: Global variables
  • Previous by thread: Re: Global variables
  • Next by thread: Re: Global variables
  • Index(es):
    • Date
    • Thread