View Single Post
08-31-17, 03:54 PM   #1
Elderin
A Deviate Faerie Dragon
Join Date: Nov 2012
Posts: 17
Looking for Broken Code Help

I am having a timing issue show up in one of my addons and I'm hoping there is an elegant fix.

The addon has a frame to which an event handler is attached and the frame registers for the "ADDON_LOADED" AND "PLAYER_ENTERING_WORLD" events.

The event handler checks for the appropriate events; along with the addon name in the case of the "ADDON_LOADED" event.

Currently during the "ADDON_LOADED" event processing only a notification that the addon is loaded is produced.

It is in the "PLAYER_ENTERING_WORLD" event processing that my issue is occurring. Prior to the recent 7.3 patch all was working good. That processing makes a call to the following module

Code:
local function GetMyStats(getFullName)
	local pName = "me";
	local pRank = -1;
	local pOcls = false;
	local rName ="Realm Name";
	
	pName, rName = UnitFullName("player");  -- player name, player realm
	if (getFullName) then
		pName = pName.."-"..rName;
	end;
	if (IsInGuild()) then
		local gn, rn, ri, gr = GetGuildInfo("player");  -- guild name, rank name, rank index, guild realm
		if (gr == nil) then  -- guild realm is nil if it is the same as the player's realm
			gr = rName;
		end;
		if (ri) then
			GuildControlSetRank(ri + 1);
			print("Guild Name: "..(gn or "nil")..", Guild Realm: "..(gr or "nil").."\nGuild Rank Index: "..(ri or "nil")..", Rank Name: "..(rn or "nil"));
			local gcl, gcs, ocl, ocs = GuildControlGetRankFlags();
			for i, v in ipairs({GuildControlGetRankFlags()}) do
				local flag = _G["GUILDCONTROL_OPTION"..i];
				print (ri, i, flag, v);
			end;
			if (ocl and ocs) then
				pOcls = true;
			end;
			pRank = ri;
		end;
	end;
	return pName, pRank, pOcls;
end;
First, the GuildControlSetRank() function is now marked protected in the 7.3 release. Included in red in the code above, but actually commented out in my current code. This seems to cause the GuildControlGetRankFlags() to malfunction and return false for all the flags. That in itself is a separate issue and i am including it just in case someone may have some insight about it.

Second, my primary issue is when the addon is first loaded and the "PLAYER_ENTERING_WORLD" fires for the first time, the function GetGuildInfo("player") is returning all nil values except for the rank index which is returned as zero. If while in game I then perform a /reload, the new call to GetGuildInfo("player") returns all values properly loaded. The output of the first time run is shown below.

Code:
Guild Name: nil, Guild Realm: nil
  Guild Rank Index: 0, Rank Name: nil

0 1 Guildchat Listen false
0 2 Guildchat Speak false
0 3 Officerchat Listen false
0 4 Officerchat Speak false
0 5 Promote false
0 6 Demote false
0 7 Invite Member false
0 8 Remove Member false
0 9 Set MOTD false
0 10 Edit Public Note false
0 11 View Officer Note false
0 12 Edit Officer Note false
0 13 Modify Guild Info false
0 14 Create Guild Event false
0 15 Guild Bank Repair false
0 16 Withdraw Gold false
0 17 Create Guild Event false
0 18 Requires Authenticator false
0 19 Modify Bank Tabs false
0 20 Remove Guild Event false
After a /reload the guild information is correctly loaded but the flags continue to be false as shown. So, I am wondering if there might be a different event that that I need to use to get the guild info properly loaded the first time. Or, perhaps a call first to some other system function to cause it to be available sooner.

Originally, I made the call to the function shown during the "ADDON_LOADED" event processing but discovered that the player's realm name from UnitFullName() was not available until after the "PLAYER_ENTERING_WORLD" event fired. So, I moved it to the "PLAYER_ENTERING_WORLD" event processing and it has apparently been working until this recent release.

Thank for any help or ideas.
  Reply With Quote