View Single Post
09-02-15, 03:34 AM   #10
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Originally Posted by Dridzt View Post
I'm no longer playing, but have you tested it?
I'd been using it for quite a while with no issues, I don't think chatcode has changed significantly.
It's not really a matter of chatcode. It's a matter of how the function works. Calling a function as owner:function() will pass owner as the hidden argument self, meaning any code within that function that refers to self will change the calling widget.

As an example, when you create a frame or button, it will inherit a lot of global functions which can be used to modify the widget, but these functions expect the widget to pass itself as the first argument. This is what the colon operator does in lua.

What you attempt to do in that snippet is call the function Clear() that is attached to SELECTED_CHAT_FRAME, without giving the function the actual frame that you intend to clear.

Example of difference between dot and colon operator:
Lua Code:
  1. function SetID(self, value)
  2.     self.ID = value
  3. end
  4.  
  5. owner.SetID = SetID -- attach function to widget
  6.  
  7. owner:SetID(1) -- passing itself as the hidden argument self
  8.  
  9. owner.SetID(self, 1) -- calling the function without hidden argument
  10.  
  11. owner.SetID(1) -- error, function will try to add nil value to an integer
  12.  
  13. owner.SetID(someOtherFrame, 1) -- uses the function SetID on owner to change someOtherFrame
__________________

Last edited by MunkDev : 09-02-15 at 09:01 AM.
  Reply With Quote