View Single Post
08-30-17, 07:21 AM   #8
Terenna
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 105
Munk,

Thank you for the feedback. I've seen others use
Lua Code:
  1. frame:SetScript("OnEvent", function(self, event, ...)
  2.     if self[event] then
  3.         self[event](self, ...)
  4.     end
  5. end)

And I get the concept of how it works, but I don't truly understand the syntax. My understanding is this: we see if the event is a table key of our function table with
Lua Code:
  1. if self[event] then
. If this passes, then it runs a function that has the same name as the event.

Later in the code you name the function like:
Lua Code:
  1. function frame:PLAYER_ENTERING_WORLD(...)
  2.     -- code
  3. end

but wouldn't this create a global function as there's no local before the function? Or is it still localized because that function is bound to (in this case) the STF frame from the initial SetScript?

Additionally, I don't understand how you would upvalue a table value. I understand that an upvalue look up is faster than a table look up, especially three table look ups, I just don't fully grasp how you would do it.

Thank you for everyone's comments and feedback. It has been very helpful.
  Reply With Quote