• 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
Newbie Question: Script Objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Newbie Question: Script Objects


  • Subject: Newbie Question: Script Objects
  • From: Simon Brown <email@hidden>
  • Date: Sun, 16 Feb 2003 17:17:55 +0000

Hello,

I'd like to know if my assumption that properties declared at the root level
of script objects persist only as long as the parent script app is running
and will be reset next time the whole script is executed (if not, there's no
point in me trying to use a script object for what I'm trying to achieve).

I would also like to know why only one of the following scripts works,
dependent on the position of the script object in the script:

Script 1: This works
(* This version DOES work, seemingly because the myHandlers script object
is ABOVE the non-'Run' handler - anotherHandler() - that calls it *)

property x : 0

--NB Script object at TOP of script
script myHandlers
on increment()
set x to x + 1
display dialog "Count is now " & x & "."
end increment
end script


on run
tell myHandlers to increment() --this call works OK in both versions
log "Run Handler called the Script Object, x is now " & x
anotherHandler()
end run

on anotherHandler()
tell myHandlers to increment()
log "AnotherHandler called the Script Object, x is now = " & x
end anotherHandler


Script 2: This doesn't work
(* This version doesn't work, seemingly because the myHandlers script object
is BELOW the non-'Run' handler - anotherHandler() - that calls it *)

property x : 0

on run
tell myHandlers to increment() --this call works OK in both versions
log "Run Handler called the Script Object, x is now " & x
anotherHandler()
end run

on anotherHandler()
(* Next line errors - "The variable myHandlers is not defined" *)
tell myHandlers to increment()
log "AnotherHandler called the Script Object, x is now = " & x
end anotherHandler

(* NB Script object at BOTTOM of script *)
script myHandlers
on increment()
set x to x + 1
display dialog "Count is now " & x & "."
end increment
end script

TIA for whatever you can tell me to improve my understanding of this issue.
--
Simon
--------------
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Newbie Question: Script Objects
      • From: Andrew Oliver <email@hidden>
  • Prev by Date: Re: How to get Zero (0) before Month ?
  • Next by Date: Script Debugger goes renegade !
  • Previous by thread: Re: Using ticks in AS Studio??
  • Next by thread: Re: Newbie Question: Script Objects
  • Index(es):
    • Date
    • Thread