Re: more scoping aggravation
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