Okay, another problem cropped up along the same lines, figured I'd post it incase anyone else had the same issue:
Code:
function MyMod_OnEvent()
if event:find("PLAYER_ALIVE") then
GuildRoster();
local name = UnitName("player");
DEFAULT_CHAT_FRAME:AddMessage("Test 1");
if ((GetGuildInfo(name)) == "Some Guild Name") then
DEFAULT_CHAT_FRAME:AddMessage("Test 2");
else
DEFAULT_CHAT_FRAME:AddMessage("Test 3");
end
end
end
This code outputs "Test 1" when you log in, nothing else. It's worth noting that the "PLAYER_ALIVE" event is the last event to fire during initial startup. There is no other event to look for after this one.
On ReloadUI it will output "Test 1" and either "Test 2" or "Test 3" as expected.
For whatever reason, GetGuildInfo will not work (at least for your own character, didn't test it on someone else's) until GuildRoster() has finished and fired a GUILD_ROSTER_UPDATE event.
Solution:
Register for the "PLAYER_LOGIN" (or later) event and the "GUILD_ROSTER_UPDATE" event.
Then...
Code:
function MyMod_OnEvent()
if event:find("PLAYER_ALIVE") then
if IsInGuild() then
GuildRoster();
else
this:UnregisterEvent("GUILD_ROSTER_UPDATE");
end
elseif event:find("GUILD_ROSTER_UPDATE") then
local name = UnitName("player");
DEFAULT_CHAT_FRAME:AddMessage("Test 1");
if ((GetGuildInfo(name)) == "Some Guild Name") then
DEFAULT_CHAT_FRAME:AddMessage("Test 2");
else
DEFAULT_CHAT_FRAME:AddMessage("Test 3");
end
end
end
The above code, as expected, will output 2 messages even when first logging in.
(Note, adding IsInGuild() prevents a "You are not in a guild." message from displaying if the person... well... isn't in a guild).
I should also point out, PLAYER_ALIVE only occurs when you actually log into the game. It has nothing to do with being alive, but does provide, according to WoWWiki, access to the talent information. This event should be avoided for initialization functions because a ReloadUI() will NOT fire these scripts. This could be potentially problematic if your mod uses a PLAYER_ALIVE function to initialize part or all of itself.
One last aside, through my testing I've discovered that the GetGuildInfo() function doesn't seem to work on normal unitID's. It appears to require a character name as a string. All attempts to call GetGuildInfo("player") failed for me (I think the exited the script without warning, but I must admit that it's been a while since I tried it), so I assume this is the case.