Local variables are....just that, local. You can only see them in ...field they get declared in. For instance, if you declare a local in the upper file (the main chunk) outside of any blocks ('do's, 'if-then's, functions, etc) they're available to the whole file and only that file. But if they're declared in a block, they are available to that block. You can also declare a local without assigning a value to it to ensure that local gets declared in an upper level than where it will be assigned. (Just simply write 'local myVar'.)
There's a really nice page regarding Scope on WoWWiki.
Boy, when you're mistaken, you get all kinds of attention, but when you're right, you get crickets... :p~
Quote from egingell »
-- In terms of functionality, this code
-- is identical to this code
MyFrameName = CreateFrame('Frame')
Perhaps my use of the term "identical" is a bit overstated. I just meant that both methods would result in creating a global variable named "MyFrameName".
Quote from Bam »
Well, that depends what functionality you mean. In the second case above, the frame does not actually have a name. That is, MyFrameName:GetName() will return nil. That would mean you cannot use it with some API functions or other parts of Blizzard's code.
I usually name the frames if I have any need for using :GetName().
Quote from OrionShock »
Generaly the 2nd line is seen as
local myFrameName = CreateFrame("Frame")
Wasn't really my point, but I know local variables are always preferred over global ones.
Quote from tekkub »
Wrong. The "name" is not just the global scope variable name, but it's also passed back from frame:GetName()... which Blizzy loves to use.
Thanks for clarifying (restating) what Bam already said.