• 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: more scoping aggravation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: more scoping aggravation


  • Subject: Re: more scoping aggravation
  • From: Axel Luttgens <email@hidden>
  • Date: Mon, 17 Jan 2011 17:31:12 +0100

Le 17 janv. 2011 à 15:48, tom wible a écrit :

> i've got a utility lib, sammylib:
> ...
> global resultMsg
>
> on write_log(msg)
> 	log msg
> 	try
> 		set now to current date
> 		set end of resultMsg to (now & " - " & msg & newline as string)
> 	on error
> 		set resultMsg to {now & " - " & msg}
> 	end try
> end write_log
>
> on clear_log()
> 	set resultMsg to {}
> end clear_log
>
> on getResults()
> 	return resultMsg as string
> end getResults
> ...
> which i include & use:
>
> [...]
>
> please explain why resultMsg is local, not global as specified:-( this used to work:
>
> [...]

It seems you have re-written your sammyLib, and that there's thus a "before" and an "after"...

For example, "newline" is incorrect and always triggers an error; you want to use "return" or "linefeed".
There's also a problematic date->string coercion; better to be explicit.
Finally, variable "resultMsg" should be for sammyLib's own usage only; so, avoid to declare it as a global and define it instead as a property of that script object.

Perhaps could you give a try to this one:

	property resultMsg : {}

	on write_log(msg)
		set end of resultMsg to "" & (current date) & " - " & msg & linefeed
		log resultMsg
	end write_log

	on clear_log()
		set resultMsg to {}
	end clear_log

	on getResults()
		return resultMsg as text
	end getResults

HTH,
Axel

 _______________________________________________
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: 
 >more scoping aggravation (From: tom wible <email@hidden>)

  • Prev by Date: more scoping aggravation
  • Next by Date: Re: Posting scripts (was more scoping aggravation)
  • Previous by thread: more scoping aggravation
  • Next by thread: Re: Posting scripts (was more scoping aggravation)
  • Index(es):
    • Date
    • Thread