Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Code referenced by variable runs but variable undefined




On 9 Jul 2006, at 00:39, polibek wrote:

The dictionary doesn't explicitly mention "result" under "resize image" so I guess it doesn't. However the lines "return {imgHalfSize, imgGT1000}" and "return {imgHalfSize, imgGT1000}" don't alter the behavior of the script and I have them commented now. I think the problem is related to variable scope but I can't seem to get it right. It stills seems weird to me that the code to resize the image actually runs and then the script decides the variable is undefined.

Let's take a closer look at what happens when we try to set a variable to the result of a command that doesn't return a result, polibek.


A statement like this:
--------------
set today to current date
--------------

Is equivalent to:
--------------
current date
set today to the result
--------------

In other words, the command is first executed - and the result is then assigned to the variable.

Where a command returns no result, the variable is undefined. This becomes evident only when you try to subsequently use the variable - since that's the point at which an attempt is made to get its value:

--------------
set some_variable to beep
some_variable
--> error number -2753 [OSAUndefinedVariable]: "The variable some_variable is not defined."
--------------


Even when it has previously been assigned some other value, a variable will still be rendered undefined in such conditions:

--------------
set some_variable to "Some string."
display dialog some_variable
--> [dialog] "Some string."

set some_variable to beep
display dialog some_variable
--> [error] "The variable some_variable is not defined."
--------------

---
kai


_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/applescript-users/email@hidden

This email sent to email@hidden
References: 
 >Code referenced by variable runs but variable undefined (From: polibek <email@hidden>)
 >Re: Code referenced by variable runs but variable undefined (From: Emmanuel <email@hidden>)
 >Re: Code referenced by variable runs but variable undefined (From: polibek <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.