I'd like to preface my question with the information that I'm new to writing in LUA. With that out of the way....
I'm having a problem with an addon that I'm working on where I can't seem to get one method to call another method. For example, this works:
function MyAddon:StartSomething()
DoSomething(something);
end
function DoSomething(something)
--Stuff goes here
end
But this does not:
function MyAddon:StartSomething()
MyAddon:DoSomething(something);
end
function MyAddon:DoSomething(something)
--Stuff goes here
end
I get an error message "Attempt to call method 'DoSomething' (a nil value)" and I just don't really understand what's going on. I've also tried calling "self:DoSomething(something)" and get the same result. Any help would be greatly appreciated.
local function StartSomething()
BustAMove();
end
local function BustAMove()
CombatText_AddMessage("BOO", COMBAT_TEXT_SCROLL_FUNCTION, 0*255, 0.8*255, 1*255)
end
As for your issue, I think it has to do with how you call the function. In the first example (the working one), you call the function from - I assume - a frame or button. That function calls a second function. It works.
In the 2nd example, you call a function from a frame, which then calls another function which is part of that frame. I think that MyAddon:DoSomething() has issues with the parenting in the second example. But I can easily be wrong.
Looking at the exact code rather than representation does a lot as it provides context.
MyAddon:FunctionName() and self:FunctionName() are basically the same thing where self = MyAddon (the value of self can be different depending on the context)
The only thing I can suggest w/o seeing your actual code is: make sure you spell the function the same way in both places (DoSomething ~= Dosomething ~= DoSomehting). When I get into WTF headscratchers like that I generally copy/paste the function name so I make damn sure it's all the same.
Where are you actually calling :StartSomething() e.g.
local MyAddon = {}
function MyAddon:StartSomething()
MyAddon:DoSomething(something);
end
MyAddon:StartSomething()
function MyAddon:DoSomething(something)
print("Doing Something")
end
Will give you this error
lua: test2.lua:24: attempt to call method 'DoSomething' (a nil value)
whereas
local MyAddon = {}
function MyAddon:StartSomething()
MyAddon:DoSomething(something);
end
function MyAddon:DoSomething(something)
print("Doing Something")
end
MyAddon:StartSomething()
I'm having a problem with an addon that I'm working on where I can't seem to get one method to call another method. For example, this works:
But this does not:
I get an error message "Attempt to call method 'DoSomething' (a nil value)" and I just don't really understand what's going on. I've also tried calling "self:DoSomething(something)" and get the same result. Any help would be greatly appreciated.
As for your issue, I think it has to do with how you call the function. In the first example (the working one), you call the function from - I assume - a frame or button. That function calls a second function. It works.
In the 2nd example, you call a function from a frame, which then calls another function which is part of that frame. I think that MyAddon:DoSomething() has issues with the parenting in the second example. But I can easily be wrong.
MyAddon:FunctionName() and self:FunctionName() are basically the same thing where self = MyAddon (the value of self can be different depending on the context)
The only thing I can suggest w/o seeing your actual code is: make sure you spell the function the same way in both places (DoSomething ~= Dosomething ~= DoSomehting). When I get into WTF headscratchers like that I generally copy/paste the function name so I make damn sure it's all the same.
Will give you this error
whereas
Will work fine and dandy.
P.S. The code you say doesn't work, works fine for me.