I am working on my first addon, and am experiencing an frustrating issue. I was hoping someone could help me.
The addon allows players to specify which bosses they need and this information is shared with the rest of the guild. This is then shown in a list for each player who uses the addon to review. To keep this information up to date, I want a player that logs in to receive the latest version of the information available. To do this, I simply send a message to the guild addon channel to request this when a player logs in.
There is one issue however. When I do this in the ADDON_LOADED event on login, for some reason the message is never received by any recipients. The strange thing is, when I reload the ui instead of logging in, sending the request in the same event works fine. Also sending it later manually works. I've tried a few different events that are generated on logging in like PLAYER_LOGIN, but that doesn't help either.
It seems like the communication channels take a while to be initialized when logging in the first time.
I couldn't find anyone else having this issue. I am considering temporarily registering for the OnUpdate event to send the message with a delay, but that seems like an excessively complex way to solve this.
Any thoughts on solving this problem? I've attached a minimal version of the addon that reproduces the problem. It sends a message to itself on ADDON_LOADED, and when that message is received it should send a message back. The message is never received however.
I just tried doing it on the first GUILD_ROSTER_UPDATE, but it seems like the channels still aren't ready by then. Seems like the only solution is adding a delay.
If you want to be super-flexible in cases of network lag or slow server databases, you might do something along the lines of:
- have your startup code register for GUILD_ROSTER_*
- initialize a persistent counter to, say, 3 or 5 or so
- inside the corresponding handler, start with code like
if not IsInGuild() then return end
local number_in_guild, number_online = GetNumGuildMembers()
if number_in_guild == nil or number_in_guild == 0 then
the_persistent_counter = the_persistent_counter - 1
if the_persistent_counter > 0 then
GuildRoster() -- request updated info
print "repeatedly failed to get guild info, bailing out"
the_persistent_counter = nil
-- Now you know you can send to guild-related channels, and you have
-- locally cached membership numbers.
This way there's no delays longer than those that the network and game client inherently impose on you, but your code will also adjust to longer delays if needed, and fail gracefully in the worst case.