Markk 2 Report post Posted January 11, 2017 I'm new to programming for WoW. I'm trying to backport a small addon, but I'm having issues with self being nil. Here is the complete code (excluding the XML). As one can see, I have commented out some functions that call on self such as on lines 24 and 32. This is because I was getting self being nil errors. But now it seems to have gotten to the point that I can't avoid these errors. Now line 6 also gives nil errors for self. This is when updateFS is being called from OnEnter and OnLeave, but it might be safe to assume this is an issue regardless of which event calls it. It am new to Lua and WoW programming, but it is my understanding that when doing something like tab:SetScript("OnEnter", OnEnter) the event (first arg of SetScript) will pass its args to the function that will be called (second arg of SetScript). According to this, OnEnter has self (reference to the frame for which the event was called) as the first arg. Everything I've read leads me to believe that. However, nothing I've read about this has been for 1.12, so I think that therein lies the issue if it isn't human error. My other hunch is that I may have to do everything event related through XML because I was having issues getting OnLoad to work doing it all through Lua (though the issue here is that self is nil, not that functions aren't being called for events). I haven't browsed through many addons yet to see how this is dealt with elsewhere. However, one that I saw which deals with events on frames used XML for all events and was using this (same as self) in the event functions. I'll try that tomorrow but I figured I might as well ask here too; I might get a response over night. So, do events not pass self in 1.12, or am I doing something wrong? If it's the former, how can I accomplish the same thing in 1.12? 0 Share this post Link to post Share on other sites
Shino 27 Report post Posted January 11, 2017 They are not. Depending how you init it. Having a function in some kind of XML object inititalized will result in the usage of this. Else try you have to use globals. The self variable can be used if you have functions like this: MyObject:MyFunction() self:DoSomething() end cheers! 0 Share this post Link to post Share on other sites
shirsig 18 Report post Posted January 11, 2017 (edited) Self is a language feature of lua where you have the implicitly defined local variable self holding the first parameter passed to the function available within the scope of a function defined in a table with the colon syntax like so: function t:foo() -- here you can use self which holds the first parameter to foo end Further there is also the colon syntax to call a function on a table like t:foo(). This implicitly passes t to foo as the first parameter. This is generally used together with the self feature though that is not necessary and they are technically independent features. Additionally in vanilla wow the global variable "this" which has no special meaning in lua is used for something similar to self within event handlers. Before the client runs your event handlers it assigns the object the handler was defined on to "this" and possible further arguments to the handler to global variables "arg1", "arg2", "arg3" etc. and for the OnEvent handler also the name of the event to the global variable "event". Edited January 11, 2017 by shirsig 0 Share this post Link to post Share on other sites
Markk 2 Report post Posted January 11, 2017 Thanks to both of you. I just had to use this as the first argument for the event handlers' calls to the updateFS function. Was this changed in later versions of WoW so that it works similar to how I originally described it? Unrelated question: is there an alternative to hooksecurefunc in 1.12? I'm guessing the reason errors are thrown is because it doesn't exist in 1.12. Should I just try a normal post-hook and hope it works? 0 Share this post Link to post Share on other sites