Hi,
Could anyone help me with my code? I register two events: PLAYER_ENTERING_WORLD and GROUP_ROSTER_UPDATE. Then run functions I have assigned to the events but it doesn't do exactly what I need.
A simple code (below) is supposed to do two things: (1) print a welcome message and (2) print a list of players in a group when I join a group as well as a player joins or leaves that group (or a raid I guess). It does prints a welcome message but it always prints: "The list of players is empty"--if someone asks, I tested when being in a party
The last message is in the second if subblock in "getlistofplayers()" function. This part is reached when API's "GetHomePartyInfo()" returns nil. It looks like this API function always returns nil! I cannot find what is wrong: the event or the API function.
I used this source for everything I looked for:
http://wowprogramming.com/docs
and it seems like a decent source. I hope someone can help
Thanks.
The codes are below.
TOC file:
Code:
## Interface: 60200
## Title: Info Addon
## Notes: Bla bla
## SavedVariables: InfoAddonDB
## Author: Me
## Version: 0.1
infoaddon.lua
Code:
local InfoAddonPlayerInfoFrame,events = CreateFrame("FRAME"),{};
local redcolour, defaultcolour = "|cFFFF0000", "|r";
-- local functions
local function getwelcomemessage()
return "Hello in my very first addon!";
end
local function getlistofplayers()
return GetHomePartyInfo();
end
local function printlistofplayers(plist)
if plist then
local print = print;
for k,v in pairs(plist) do
print(v);
end
else
-- print(redcolour .. "The list of players is empty" .. defaultcolour);
print("The list of players is empty");
end
end
-- Event handlers
function events:PLAYER_ENTERING_WORLD(...)
print(getwelcomemessage())
end
function events:GROUP_ROSTER_UPDATE(...)
printlistofplayers(getlistofplayers());
end
for k,v in pairs(events) do
InfoAddonPlayerInfoFrame:RegisterEvent(k);
end
-- Set Script
InfoAddonPlayerInfoFrame:SetScript("OnEvent", function (self, event, ...)
events[event](self, ...);
end);