View Single Post
04-18-09, 12:13 AM   #12
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Originally Posted by Azul View Post
What is wrong with this? It says that foo is global, and that it's nil.. when obviously it should be local (they all should), and not nil..

Code:
local frame=CreateFrame("Frame")
frame:SetScript("OnUpdate",function(self)
	if not foo then local foo,bar,text="foo","bar","" end
	text=foo..bar
end)

I'm really starting to hate lua with a passion. To bad there are no alternatives.
Ok, no offense mate, but don't edit a different code into it when people are trying to help you figure out the original. I was confused there for a sec...

Try separating the function out to test functionality better:
Code:
local f = CreateFrame("Blah")
f:SetScript("OnUpdate", testfunction(self))

function testfunction(frame)
    if not foo then 
        local foo = "foo"
        local bar = "bar"
    end
    text=foo..bar
    DEFAULT_CHAT_FRAME:AddMessage(text)  -- test to make sure everything goes smoothly
end
Also note that I removed local text = "" as you don't need it. It's already going to be overridden each time without having to manually clear it. After you get it working how you want, then go back and optimize the code (as haste pointed out).

Last edited by Sythalin : 04-18-09 at 12:15 AM. Reason: code typo