Wednesday, April 18, 2012

In the name of all that is holy, why can't I AddMessage to my MessageFrame

So, I'm getting back into writing some mods, and for the life of me I can't figure out why I can't addMessage to MessageFrames or ScrollingMessageFrames. I don't get an error, and the script keeps executing, it just doesn't show up. Did the 2.0 patch do something?

To keep things simple, I took the excellent XML tutorial and just added a MessageFrame to the editing frame and changed it so when clicking the button, it writes to the MessageFrame and the chat frame. The message shows up fine in the chat, just not in the MessageFrame.

I realize I'm probably doing something insanely obvious wrong, just not seeing it.

The XML:


Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.blizzard.com/wow/ui/
C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">

<Script file="Simple.lua"/>

<Frame name="SimpleFrame" parent="UIParent" visible="true">
<Size>
<AbsDimension x="200" y="333" />
</Size>
<Anchors>
<Anchor point="CENTER"/>
</Anchors>
<Backdrop bgFile="Interface\TutorialFrame\TutorialFrameBackg round"
edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true">
<EdgeSize>
<AbsValue val="16"/>
</EdgeSize>
<TileSize>
<AbsValue val="32"/>
</TileSize>
<BackgroundInsets>
<AbsInset left="5" right="5" top="5" bottom="5"/>
</BackgroundInsets>
</Backdrop>
<Layers>
<Layer level="ARTWORK">
<FontString name="Simple_Text" inherits="ChatFontNormal" text="Type in something:">
<Anchors>
<Anchor point="TOP">
<Offset>
<AbsDimension x="0" y="-33"/>
</Offset>
</Anchor>
</Anchors>
</FontString>
</Layer>
</Layers>

<Frames>
<Button name="Simple_CloseButton" inherits="UIPanelCloseButton">
<Anchors>
<Anchor point="TOPRIGHT">
<Offset>
<AbsDimension x="-3" y="-3" />
</Offset>
</Anchor>
</Anchors>

<Scripts>
<OnClick>Simple_Close();</OnClick>
</Scripts>
</Button>

<EditBox name="Simple_EditBox" letters="50">
<Layers>
<Layer level="BACKGROUND">
<Texture name="Simple_Background">
<Color r=".2" g=".2" b=".2" a="1"/>
</Texture>
</Layer>
</Layers>
<Size>
<AbsDimension x="190" y="20"/>
</Size>
<Anchors>
<Anchor point="TOPLEFT">
<Offset>
<AbsDimension x="5" y="-66"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnEnterPressed>
Simple_AcceptButton:Click();
</OnEnterPressed>
</Scripts>
<FontString inherits="ChatFontNormal"/>
</EditBox>

<Button name="Simple_AcceptButton" inherits="OptionsButtonTemplate" text="GO!">
<Anchors>
<Anchor point="BOTTOM">
<Offset>
<AbsDimension x="0" y="220"/>
</Offset>
</Anchor>
</Anchors>

<Scripts>
<OnClick>Simple_ButtonClick();</OnClick>
</Scripts>
</Button>
<MessageFrame name="Simple_MessageFrame" hidden="false">
<Size>
<AbsDimension x="200" y="180" />
</Size>
<Anchor point="BOTTOM">
<Offset>
<AbsDimension x="0" y="20"/>
</Offset>
</Anchor>
</MessageFrame>
</Frames>

</Frame>


</Ui>

The LUA:


Code:
function Simple_ButtonClick()
DEFAULT_CHAT_FRAME:AddMessage(Simple_EditBox:GetText());
Simple_MessageFrame:AddMessage(Simple_EditBox:GetText());
Simple_EditBox:SetText("");
end

function Simple_Close()
SimpleFrame:Hide();
end

Thanks!!|||Just tested your code. It looks like the messageframe is just not visible.

I added a backdrop to this frame (should be possible because messageframe inherits all attributes from frame). Nothing to see. But I don't know why. :)|||Quote:








Just tested your code. It looks like the messageframe is just not visible.

I added a backdrop to this frame (should be possible because messageframe inherits all attributes from frame). Nothing to see. But I don't know why. :)




I am running into the exact same issue. So you are saying that adding a backdrop would make the messageframe visible?

I don't see a visible property, but there is a hidden property. I assumed that would default to hidden="false". hmm.|||I think frames default to hidden? Try FrameName:Show().|||Quote:








I think frames default to hidden? Try FrameName:Show().




I tried it, but it complained about it. In the VS addon studio, it isn't recognized as a function so unless you know where I can find such a function, I must be on the wrong track. Is there a list of required objects that need to be under the <messageFrame>?|||Your code has two problems in the XML:

1) Your anchors are not defined properly, so they are being ignored. You need to have "Anchors" before the "Anchor" part of your MessageFrame, or else the anchors won't happen. So:


Code:
<Anchors>
<Anchor>
...
</Anchor>
</Anchors>

2) Your message frame needs a font string. Right now, it has no font attached to it. Like the EditBox, it needs one as well =) So add:


Code:
<FontString inherits="ChatFontNormal"/>

To it.

In summary:

Copy this in for your XML for the MessageFrame:


Code:
<MessageFrame name="Simple_MessageFrame" hidden="false">
<Size>
<AbsDimension x="200" y="180" />
</Size>
<Anchors>
<Anchor point="BOTTOM">
<Offset>
<AbsDimension x="0" y="20"/>
</Offset>
</Anchor>
</Anchors>
<FontString inherits="ChatFontNormal"/>
</MessageFrame>

That works on my end, so it should work out for you. The text location in the MessageFrame will default to the center. If you don't want that use:


Code:
<FontString inherits="ChatFontNormal" justifyH="LEFT"/>

Instead.|||trust moon hes like the code god.|||Quote:








2) Your message frame needs a font string. Right now, it has no font attached to it. Like the EditBox, it needs one as well =)




That was top notch advice. I thank you for your time. I am somewhat disappointed that there are some blocks that are required and some that aren't, and that there is no error checking in the Visual Studio AddOn Studio so I can figure that out. Anyway, it is working now, and there is one mistake I don't ever have to make again.

No comments:

Post a Comment