Nailed it.
The prehook function needs to be:
Lua Code:
function OnGuildIdChanged(self)
local guild_id = self.guildId
...etc...
end
For some reason the function GetGuildId() always returns 1 in this context. And GUILD_SHARED_INFO.guildId is always one behind, because the prehook function gets called
before the handler for EVENT_GUILD_DATA_LOADED in the GuildSharedInfo API class, and that handler is what changes the value in GUILD_SHARED_INFO.
Thanks for pointing me in the right direction.