Trouble / Confusion on Adding a 'Chat Tab' Through Code

Hello everyone, I’m having some trouble/confusion on how to go about creating an additional ‘chat tab’ in addition to the default tabs of ‘General’ and ‘Combat’ - effectively a tab where an addon can dump all its output to.

I thought calling ‘FCF_OpenNewWindow(“name”)’ would do the job, but when I look around ‘nothing’ is there despite my debugging telling me that my new code created tab is correct. When using /framestack, I can see that (as in the image) that the new (4th tab in this case) edit box is there, but I can’t find any other elements relating to it. Additionally, entering input into it / using ‘addmessage()’ directly to it results in nothing, nor does it pickup anything done in game (though ‘general’ seems to pick it up just fine).

So, I know I’m missing something, I just don’t know what it is…/sad. Also, the terminology gets a bit confusing for UI since I guess the root element of all UI are ‘frames’, which may or may not be called ‘frames’ in the code (like a ‘chat tab’ is also a ‘frame’ correct?), it kind of running together on me.

Any help is appreciated, thank you for reading.
http://cubeupload.com/im/blitzer/chatframeissue.jpg

local newChat = FCF_OpenNewWindow("new Chat")

TSMCUSTOM.CustomPrint("checking chat windows") --says it exists
for i = 1, NUM_CHAT_WINDOWS do
	TSMCUSTOM.CustomPrint("i: " .. i)
	TSMCUSTOM.CustomPrint(GetChatWindowInfo(i))
end

--[
local name, fontSize, r, g, b, alpha, shown, locked, docked, uninteractable = GetChatWindowInfo(4) --shows correct name, alpha, docked index --shown yes, locked no
TSMCUSTOM.CustomPrint("GetChatWindowInfo(4).name: " .. name)
TSMCUSTOM.CustomPrint("GetChatWindowInfo(4).alpha: " .. alpha)
TSMCUSTOM.CustomPrint("GetChatWindowInfo(4).shown: " .. tostring(shown))
TSMCUSTOM.CustomPrint("GetChatWindowInfo(4).locked: " .. tostring(locked))
TSMCUSTOM.CustomPrint("GetChatWindowInfo(4).docked: " .. docked)
--]

for i = 1, NUM_CHAT_WINDOWS do
	_G["ChatFrame" .. i]:AddMessage("This is ChatFrame"..i, 0, 0, 0, GetChatTypeIndex("SAY")) --general and manual tabs are fine, coded one does nothing
end

_G["ChatFrame" .. 4]:AddMessage("test test test") --results in nothing

All UI elements (that you’re likely to code for) are Regions which derive from UIObject which has parentage which is inaccessible to you as an AddOn coder.

There’s a detailed (and for future readers, likely updated), explanation of this https://wow.gamepedia.com/Widget_API but the gist of it is here:

...
└──UIObject*
   ├──...
   └──Region*
      ├──LayeredRegion*
      │  ├──FontString
      │  └──Texture
      │     ├──Line
      │     └──MaskTexture
      └──Frame
         ├──Browser
         ├──Button
         │  ├──CheckButton
         │  └──ItemButton
         ├──Checkout
         ├──ColorSelect
         ├──Cooldown
         ├──EditBox
         ├──FogOfWarFrame
         ├──GameTooltip
         ├──MessageFrame
         ├──Minimap**
         ├──Model
         │  └──PlayerModel
         │     ├──CinematicModel
         │     ├──DressUpModel
         │     └──TabardModel
         ├──ModelScene
         ├──MovieFrame
         ├──OffScreenFrame
         ├──POIFrame*
         │  ├──ArchaeologyDigSiteFrame
         │  ├──QuestPOIFrame
         │  └──ScenarioPOIFrame
         ├──ScrollFrame
         ├──ScrollingMessageFrame
         ├──SimpleHTML
         ├──Slider
         ├──StatusBar
         └──UnitPositionFrame

* Virtual frame which cannot be created directly.
** Restricted virtual frame. Some elements of this can be manipulated through Lua, but user-created AddOns cannot create new elements at this level (or likely below this level).

2 Likes

The last line “-- Results in nothing”, make sure you have the correct tab selected to see the text message that has been added.

The code below: run the first time and you will see the message "Just getting started here!!!" because creating the new tab also sets it to focus. A /reload, and you won’t see the message until you select the tab that was created.

local myChat
local f = CreateFrame("Frame")
f:SetScript("OnEvent", function(self, event, ...)
	local found
	for i = 1, NUM_CHAT_WINDOWS do
		local name = GetChatWindowInfo(i)
		if name == "new Chat" then
			found = i
			break
		end
	end
	if found then
		myChat = _G["ChatFrame" .. found]
	else
		myChat = FCF_OpenNewWindow("new Chat", true)
	end
	myChat:AddMessage("Just getting started here!!!", 1, 1, 1)
end)
f:RegisterEvent("PLAYER_LOGIN")

FCF_OpenNewWindow will keep adding new windows permanently until you remove/clear them all or reset your entire chat setup with FCF_ResetAllWindows() so you might end up with multiple channels with the name “new Chat” if you don’t check for its existence first.

1 Like