local function getGeneral(...)
for i = 1, select("#", ...), 2 do
local id, name = select(i, ...)
if not string.match(name,'General', ...) == nil then
SendChatMessage(name..":"..id, "WHISPER", nil, "Nirgáli")
local general_chat = getGeneral(GetChannelList())
Basically, I want to get the general chat id, so I loop through the list of channels looking for one that starts with General. Is there a better way to write this perhaps?
Use the Blizzard global string so it works in all locales without hardcoded translations. Also, I'd just use a recursive function instead of looping over the vararg with multiple select calls.
local function FindGeneralChat(channel, ...)
if channel then
if strfind(channel, GENERAL) then
local generalChat = FindGeneralChat([URL="http://wowpedia.org/API_EnumerateServerChannels"]EnumerateServerChannels[/URL]())
That enumerates strings. The function returns a string when I need the channel ID for SendChatMessage. I've tried different approaches, also using your idea, but nothing seems to work for me. I don't want to use any libraries. I'll just keep plugging away at it until I figure it out.
Interestingly that code was the first revision I tried after you're first suggestion. It still returned a nil value. I imagine something else in my code is causing this. The problem was the placement of the local generalChat = ... I ended up moving it to another function and it worked fine. Perhaps the channels weren't loaded fast enough before the function was called? Anyway, I appreciate you posting this last bit, it confirmed I was going down the right path.
As I posted in your other thread, you should be calling the function to find the General chat's ID each time you want to use it.
For example, you can log in with General chat in slot 1, then leave General chat, enter a city and get Trade in slot 1, and then rejoin General. It's now in slot 2, and your addon would send its messages to Trade chat instead because it's still sending to channel 1.
So, just move the whole "local generalChat = FindGeneralChat(GetChannelList())" line into the function where you actually read the "generalChat" variable. For example:
local generalChat = FindGeneralChat(GetChannelList())
if generalChat then
SendChatMessage("CHANNEL", message, nil, generalChat)
print("You are not in General chat!")