I wrote an addon whose purpose is to display the name, toon name, and level of all of my RealID friends that are currently online. It works perfectly with one exception: all the data is not present at the event-firing. This causes an error about concatenating nil fields (even though I assigned defaults) which is unrecoverable without a reload.
What would be the best method to delay the EventHandler script for 1-2 seconds? Or better yet, is there a better set of events to monitor?
Lua Code:
-- People Detector for CormanthorUI
-- Create the color table (redundant, but necessary)
local colorScheme = {
death_knight = "C41F3B",
druid = "FF7D0A",
hunter = "ABD473",
mage = "69CCF0",
monk = "558A84",
paladin = "F58CBA",
priest = "FFFFFF",
rogue = "FFF569",
shaman = "0070DE",
warlock = "9482C9",
warrior = "C79C6E"
}
-- Create the frame and listen to events
local cormPD = CreateFrame("frame", "PeopleDetector", Minimap)
cormPD:SetSize(200,100)
cormPD:SetPoint("TOPRIGHT", Minimap, "TOPLEFT", -10, 0)
cormPD:RegisterEvent("PLAYER_ENTERING_WORLD")
cormPD:RegisterEvent("BN_FRIEND_ACCOUNT_OFFLINE")
cormPD:RegisterEvent("BN_FRIEND_ACCOUNT_ONLINE")
cormPD:RegisterEvent("PLAYER_FLAGS_CHANGED")
local text = cormPD:CreateFontString()
text:SetFont("Fonts\\FRIZQT__.TTF", 10, "THINOUTLINE")
text:SetPoint("TOPRIGHT", cormPD)
text:SetJustifyH("RIGHT")
local myRealm = GetRealmName()
-- List the first name and toon name of all RealID friends
local function Event_Handler(self, event, ...)
local online = select(2,BNGetNumFriends())
local list = ""
local friendName = ""
local toonName = ""
local toonClass = ""
local toonLevel = ""
local toonRealm = ""
for i = 1,online do
friendName = select(2,BNGetFriendInfo(i)) or "UNKNOWN"
toonName = select(4,BNGetFriendInfo(i)) or "UNKNOWN"
toonClass = gsub(strlower(select(8,BNGetFriendToonInfo(i,1)))," ","_") or "priest"
toonLevel = select(11,BNGetFriendToonInfo(i,1)) or 0
toonRealm = select(4,BNGetFriendToonInfo(i,1)) or myRealm
if toonRealm == myRealm then
list = list..friendName
else
list = list.."|cff0080FF"..friendName.."|r"
end
list = list.." (|cff"..colorScheme[toonClass]..toonName.."|r "..toonLevel..")\n"
end
text:SetText(list)
end
cormPD:SetScript("OnEvent", Event_Handler)