Thread Tools Display Modes
01/18/16, 04:59 AM   #1
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
Problem with guild IDs after leaving a guild -> ID = ID+MAX_GUILDS

Hey there,

as I tested something with my addon FCOGuildInfo I've joined and left a guild to see what the events for joining/leaving a guild do.

After joining a guild:
The function GetNumGuilds() gets me the correct number of my new guilds: 5
The function GetGuildName(guildId) gets me the correct name of all my 5 guilds (IDs 1 to 5).

Do not logout in between here!

After leaving the joined guild later on:
The function GetNumGuilds() gets me the correct number of my guilds left: 4
The function GetGuildName(guildId) gets me an empty string?
I've tested IDs 1 to 5 -> Empty string

After that I just tested IDs > 5 and all of sudden:
ID6 = ID1 (Guild 1) -> Name was found correctly
ID7 = ID2 (Guild 2) -> Name was found correctly
ID8 = ID3 (Guild 3) -> Name was found correctly
ID9 = ID4 (Guild 4) -> Name was found correctly

I don't know if this is normal but for me it looks like a bug?
Maybe they copy the guild ids to ID+MAX_GUILDS (or something like this) as you remove a guild, so they can reorg something in the background.
But it seems as if it wa snot moved back to IDs 1 to 4 properly afterwards.

Anyone here encountered this too?

Edit:
The function GetGuildId() always will return 6 at this moment, even if I change the active guild in the roster...

Edit2:
After joining the same guild again the things get even more weird:
Guild 1 was moved to guildID 5
Guild 2 was moved to guildID 6
Guild 3 was moved to guildID 7
Guild 4 was moved to guildID 8
Guild 5 was moved to guildID 9

So everything was moved from starting ID 6 to starting ID 5 (-1)???

Last edited by Baertram : 01/18/16 at 05:18 AM.
  Reply With Quote
01/18/16, 05:03 AM   #2
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
When you leave/Join a guild, the GetGuildId() is mandatory, while doing test, game often returned me things like


1st = 1
2nd = 17
3rd = 24
4th = 12
5th = 46

Itr reverts correctly at next ReloadUI to 1/2/3/4/5.
so, just use GetGuildId(), always.
  Reply With Quote
01/18/16, 05:46 AM   #3
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
No, I cannot say the same Ayantir!

After reloadui it was not reset to normal 1,2,3,4,5 but it stayed at 6+.
After a logout it was reset to the normal 1,2,3,4,5 though.

But how am I able to loop over all given guilds (from guild 1 to 5) if they do not use the guild ids 1 to 5 but 5 to 9, and GetGuildId() will return something like 6?
  Reply With Quote
01/18/16, 05:48 AM   #4
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
You need to differ between guildIndex and guildID.
guildIndex is what you get when you use GetNumGuilds() and it will always be 1 to number of guilds, guildID is an arbitrary number and cannot be known before using GetGuildId(guildIndex). Don't assume that guildID is in the range 1-5 or even in the "correct" order. guildIndex will always reflect the order you joined the guilds in, but the index might change if you leave a guild. If you want to save something for a guild, it's safest to use the guild name, as this will never change.

If you use the guild joined and left events
Code:
EVENT_GUILD_SELF_JOINED_GUILD (integer eventCode, integer guildId, string guildName)
EVENT_GUILD_SELF_LEFT_GUILD (integer eventCode, integer guildId, string guildName)
there is also another catch: The guildId is not the local guildId, but for some reason the server-wide id of the guild. So for example when you create a new guild, you get the number of guilds that have been created so far on that server, as it seems to be a simple incremental id.
In order to get the local id you need to use this code inside the eventhandler:
Lua Code:
  1. local guildId = GetGuildId(GetNumGuilds())

edit: For iterating over all your guilds, use this code:
Lua Code:
  1. for guildIndex = 1, GetNumGuilds() do
  2. local guildId = GetGuildId(guildIndex)
  3. -- do something
  4. end

Last edited by sirinsidiator : 01/18/16 at 05:50 AM.
  Reply With Quote
01/18/16, 05:52 AM   #5
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
Ok, thanks for the clarification.
I missunderstood the guildId and GetGuildId() functions then.

Originally Posted by sirinsidiator View Post
You need to differ between guildIndex and guildID.
guildIndex is what you get when you use GetNumGuilds() and it will always be 1 to number of guilds, guildID is an arbitrary number and cannot be known before using GetGuildId(guildIndex). Don't assume that guildID is in the range 1-5 or even in the "correct" order. guildIndex will always reflect the order you joined the guilds in, but the index might change if you leave a guild. If you want to save something for a guild, it's safest to use the guild name, as this will never change.

If you use the guild joined and left events
Code:
EVENT_GUILD_SELF_JOINED_GUILD (integer eventCode, integer guildId, string guildName)
EVENT_GUILD_SELF_LEFT_GUILD (integer eventCode, integer guildId, string guildName)
there is also another catch: The guildId is not the local guildId, but for some reason the server-wide id of the guild. So for example when you create a new guild, you get the number of guilds that have been created so far on that server, as it seems to be a simple incremental id.
In order to get the local id you need to use this code inside the eventhandler:
Lua Code:
  1. local guildId = GetGuildId(GetNumGuilds())

edit: For iterating over all your guilds, use this code:
Lua Code:
  1. for guildIndex = 1, GetNumGuilds() do
  2. local guildId = GetGuildId(guildIndex)
  3. -- do something
  4. end
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Problem with guild IDs after leaving a guild -> ID = ID+MAX_GUILDS


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off