View Single Post
08-30-17, 07:34 AM   #9
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
With the API "CreateFrame", what that really does is create a table and inject it with methods (in essence).
When you create a function "frame:PLAYER_LOGIN" you are basically assigning that to the table "frame".

Lua Code:
  1. local t = {
  2.     PLAYER_LOGIN = function() end
  3. }
is the same as
Lua Code:
  1. local t = {}
  2. function t:PLAYER_LOGIN()
  3. end

So in SetScript in that example, you're calling the function by its table key in the current table (or frame rather), which in the context of SetScript is "self".
You could just as well (in the SetScript block) call it by "frame[event]" (just in case the "self" variable confuses you).
And the value for that key would be the function.

It's never global, but you can access it globally if the frame itself is global (either by variable or name, the 2nd argument in CreateFrame), by using the key (in this case PLAYER_LOGIN or any other event).

The reason you check for "self[event]" is to make sure you don't get errors when the function doesn't exist in the table.
  Reply With Quote