WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   setText or setFormattedText or ? (https://www.wowinterface.com/forums/showthread.php?t=54598)

Lazare 10-03-16 07:51 PM

setText or setFormattedText or ?
 
I have a button defined in my xml file as TRACK_QUEST_ABBREV The normal text for it is "Track". I would love to be able to change it to "UnTrack" if the quest is being tracked (like the Blizz quest log does). I copied the following Lua code from the Blizz quest log but it is giving me errors:
Lua Code:
  1. function qgc:ToggleWatch(index)
  2.     if not index then
  3.         index = GetQuestLogSelection()
  4.     end
  5.     if index>0 then
  6.         if IsQuestWatched(index) then -- already watched, remove from watch
  7.             RemoveQuestWatch(index)
  8.             TRACK_QUEST_ABBREV:SetText(TEXT("Track"))
  9.         else -- not watched, see if there's room to add, add if so
  10.             if GetNumQuestWatches() >= MAX_WATCHABLE_QUESTS then
  11.                 UIErrorsFrame:AddMessage(format(QUEST_WATCH_TOO_MANY,MAX_WATCHABLE_QUESTS),1,0.1,0.1,1)
  12.             else
  13.                 AddQuestWatch(index)
  14.                 TRACK_QUEST_ABBREV:SetText(TEXT("UnTrack"))
  15.             end
  16.         end
  17.     end
  18. end
What am I missing? The error that I get is: attempt to call method 'SetText' (a nil value) and SetFormattedText gets the very same error.
Thanks in advance for any help on this.
Cheers!

Torhal 10-03-16 08:16 PM

TRACK_QUEST_ABBREV is a variable which holds a string. :SetText and :SetFormattedText are methods for a FontString object.

Phanx 10-03-16 11:19 PM

Also, the TEXT() function is legacy code from the very earliest iterations of the Blizzard UI; you should never use it in an addon. It literally just returns the string you pass to it:

Code:

    function TEXT(text)
      return text;
    end

Just write the string you want to use.

As to the actual question:

SetText and SetFormattedText are methods that exist on font string objects -- not string values. "Font string" is a type of widget in the WoW UI API, like "texture", "frame", or "button". "String" is a type of value in the Lua programming language, like "number", "boolean", or "table".

If you want to display text, you either need to create a font string (which in turn needs to be attached to a frame):

lua Code:
  1. local frame = CreateFrame("Frame", "LazareQuestFrame", UIParent)
  2. frame:SetSize(100, 100)
  3. frame:SetPoint("CENTER")
  4.  
  5. local fontstring = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  6. fontstring:SetPoint("CENTER")

... or find the name of, or a reference to, a font string that already exists in the UI. Then you can tell it what text to display:

Lua Code:
  1. fontstring:SetText("Track")

SetFormattedText is a "shortcut" to calling string.format and SetText; these do the same thing:

Lua Code:
  1. fontstring:SetText(string.format("You have %d cats.", 42))
  2. fontstring:SetFormattedText("You have %d cats.", 42)

The difference is that SetFormattedText shifts the string.format operation over into C code, where it's (presumably) faster than running it in Lua. Unless you're doing it a million times in a row, though, you'll never notice the difference, so the main reason to use SetFormattedText is that it makes your code less verbose and more readable.

Edit:
After re-reading your post I noticed that you mentioned you think the TRACK_QUEST_ABBREV variable is referring a button. That is not correct -- the Blizzard UI code defines TRACK_QUEST_ABBREV as containing the string "Track". If you overwrote that value with a pointer to a button object, that's even worse -- not only does your code still not work, but you're also breaking any part of the default UI and other addons that expect TRACK_QUEST_ABBREV to be a string.

Please post the rest of your code.

Lazare 10-06-16 04:58 AM

The xml code is below
Code:

    <Button parentKey="TrackButton" inherits="MagicButtonTemplate" text="TRACK_QUEST_ABBREV">
                <Size x="80" y="22"/>
                <Anchors>
                    <Anchor point="LEFT" relativeKey="$parent.push" relativePoint="RIGHT"/>
                </Anchors>
                <Scripts>
                    <OnClick>
                        QuestGuru:ToggleWatch()
                    </OnClick>
                    <OnEnter>
                        GameTooltip_AddNewbieTip(self, TRACK_QUEST, 1.0, 1.0, 1.0, NEWBIE_TOOLTIP_TRACKQUEST, 1)
                    </OnEnter>
                    <OnLeave function="GameTooltip_Hide"/>
                </Scripts>
            </Button>

and the Lus is
lua Code:
  1. function qgc:ToggleWatch(index)
  2.     if not index then
  3.         index = GetQuestLogSelection()
  4.     end
  5.     if index>0 then
  6.         if IsQuestWatched(index) then -- already watched, remove from watch
  7.             RemoveQuestWatch(index)
  8.             TrackButton:SetText(TRACK_QUEST_ABBREV)
  9.         else -- not watched, see if there's room to add, add if so
  10.             if GetNumQuestWatches() >= MAX_WATCHABLE_QUESTS then
  11.                 UIErrorsFrame:AddMessage(format(QUEST_WATCH_TOO_MANY,MAX_WATCHABLE_QUESTS),1,0.1,0.1,1)
  12.             else
  13.                 AddQuestWatch(index)
  14.                 TrackButton:SetText(UNTRACK_QUEST_ABBREV)
  15.             end
  16.         end
  17.     end
  18. end


Blizzards coding from the Map/Quest is:
lua Code:
  1. if ( IsQuestWatched(questLogSelection) ) then
  2.         QuestMapFrame.DetailsFrame.TrackButton:SetText(UNTRACK_QUEST_ABBREV);
  3.         QuestLogPopupDetailFrame.TrackButton:SetText(UNTRACK_QUEST_ABBREV);
  4.     else
  5.         QuestMapFrame.DetailsFrame.TrackButton:SetText(TRACK_QUEST_ABBREV);
  6.         QuestLogPopupDetailFrame.TrackButton:SetText(TRACK_QUEST_ABBREV);
  7.     end
Which corresponds to the TrackButton sections of my code.Thank you for your help.
Cheers

Phanx 10-06-16 09:16 AM

You're not defining a global variable named "TrackButton" (nor should you) so you're now trying to call "SetText" on a nil value. The button object in the XML snippet you defined doesn't have a name (which is good) -- the "parentKey" attribute makes it accessible globally as "ParentFrame.TrackButton" or "AncestorFrame.Mothership.FlyingPopTarts.TrackButton" or something like that. However, since you did not post all of your code (seriously, why is it so hard to get people to do this?!) I can't tell you the actual path to that button you need to use in your Lua code, so you'll have to figure it out yourself.

Lazare 10-12-16 01:32 AM

The full xml code is below. I only did the section of Lua code that has anything to do with trying to change the button text. Pasting over 500 lines of Lua code that has nothing to do with it doesn't make sense to me. So the XML code fully is:
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/
..\FrameXML\UI.xsd">

    <CheckButton name="QuestGuruCheckButtonTemplate" inherits="UICheckButtonTemplate" virtual="true">
        <Size x="24" y="24"/>
        <Scripts>
            <OnEnter>
                QuestGuru.OptionOnEnter(self)
            </OnEnter>
            <OnLeave function="GameTooltip_Hide"/>
            <OnClick>
                QuestGuru.OptionOnClick(self)
            </OnClick>
        </Scripts>
    </CheckButton>

    <Button name="QuestGuruListTemplate" virtual="true" text="Quest Title Example">
        <Size x="299" y="16"/>
        <Layers>
            <Layer level="BACKGROUND">
                <Texture parentKey="selected" file="Interface\QuestFrame\UI-QuestLogTitleHighlight" alphaMode="ADD"/>
            </Layer>
            <Layer level="ARTWORK">
                <!-- number to left of quest indicating how many in group are on same quest -->
                <FontString parentKey="groupMates" inherits="GameFontNormalSmall" justifyH="RIGHT">
                    <Size x="0" y="16"/>
                    <Anchors>
                        <Anchor point="LEFT" x="8" y="0"/>
                    </Anchors>
                </FontString>
                <!-- icon for the "tag" (Daily) (Account) (Raid) (Complete) etc -->
                <Texture parentKey="tag" file="Interface\QuestFrame\QuestTypeIcons">
                    <Size x="18" y="18"/>
                    <Anchors>
                        <Anchor point="RIGHT" x="-2" y="0"/>
                    </Anchors>
                </Texture>
                <!-- checkmark to note tracked quests appears to right of normalText (anchored in the UpdateLogList) -->
                <Texture parentKey="check" file="Interface\Buttons\UI-CheckBox-Check">
                    <Size x="16" y="16"/>
                    <Anchors>
                        <Anchor point="LEFT"/>
                    </Anchors>
                </Texture>
            </Layer>
        </Layers>
        <!-- quest title/header normalText is shifted to right 20 -->
        <ButtonText parentKey="normalText" nonspacewrap="true">
            <Size x="0" y="10"/>
            <Anchors>
                <Anchor point="LEFT" x="20" y="0"/>
            </Anchors>
        </ButtonText>
        <NormalTexture file="Interface\Buttons\UI-MinusButton-UP">
            <Size x="16" y="16"/>
            <Anchors>
                <Anchor point="LEFT" x="3" y="0"/>
            </Anchors>
        </NormalTexture>
        <HighlightTexture file="Interface\Buttons\UI-PlusButton-Hilight" alphaMode="ADD">
            <Size x="16" y="16"/>
            <Anchors>
                <Anchor point="LEFT" x="3" y="0"/>
            </Anchors>
        </HighlightTexture>
        <NormalFont style="GameFontNormalLeft"/>
        <HighlightFont style="GameFontHighlightLeft"/>
        <DisabledFont style="GameFontHighlightLeft"/>
        <Scripts>
            <OnLoad>
                self.check:SetPoint("LEFT",self.normalText,"RIGHT")
            </OnLoad>
            <OnClick>
                QuestGuru.ListEntryOnClick(self)
            </OnClick>
            <OnEnter>
                QuestGuru.ListEntryOnEnter(self)
            </OnEnter>
            <OnLeave>
                GameTooltip:Hide()
            </OnLeave>
        </Scripts>
    </Button>

    <Frame name="QuestGuru" parent="UIParent" toplevel="true" clampedToScreen="true" enableMouse="true" movable="true" resizable="true" inherits="ButtonFrameTemplate" hidden="true">
        <Size x="667" y="496"/>
        <Anchors>
            <Anchor point="LEFT"/>
        </Anchors>
        <Layers>
            <Layer level="OVERLAY" textureSubLevel="-1">
                <Texture name="QGC_FramePortrait" file="Interface\QuestFrame\UI-QuestLog-BookIcon">
                    <Size x="64" y="64"/>
                    <Anchors>
                        <Anchor point="TOPLEFT" x="-9" y="9"/>
                    </Anchors>
                </Texture>
            </Layer>
            <Layer level="BACKGROUND">
                <!-- temporary fix for lua error in QuestInfo.lua:45 (questFrame.SealMaterialBG is nil) -->
                <Texture parentKey="SealMaterialBG" hidden="true"/>
                <FontString name="QGC_FrameTitleText" inherits="GameFontNormal" text="QUESTGURU_VERSION">
                    <Anchors>
                        <Anchor point="TOP" x="0" y="-5"/>
                    </Anchors>
                </FontString>
            </Layer>
        </Layers>
        <Frames>
            <!-- this is for a one-frame OnUpdate to run UpdateLog (so the function doesn't run multiple times in a frame -->
            <Frame parentKey="update" hidden="true">
                <Scripts>
                    <OnUpdate>
                        self:GetParent():UpdateLog()
                    </OnUpdate>
                </Scripts>
            </Frame>
            <!-- close button in bottomright -->
            <Button inherits="MagicButtonTemplate" text="CLOSE">
                <Size x="80" y="22"/>
                <Anchors>
                    <Anchor point="BOTTOMRIGHT" x="-6" y="4"/>
                </Anchors>
                <Scripts>
                    <OnClick>
                        self:GetParent():Hide()
                    </OnClick>
                </Scripts>
            </Button>
            <!-- abandon button in bottomleft -->
            <Button parentKey="abandon" inherits="MagicButtonTemplate" text="ABANDON_QUEST_ABBREV">
                <Size x="80" y="22"/>
                <Anchors>
                    <Anchor point="BOTTOMLEFT" x="4" y="4"/>
                </Anchors>
                <Scripts>
                    <OnClick>
                        SetAbandonQuest();
                        local items = GetAbandonQuestItems();
                        if ( items ) then
                            StaticPopup_Hide("ABANDON_QUEST");
                            StaticPopup_Show("ABANDON_QUEST_WITH_ITEMS", GetAbandonQuestName(), items);
                        else
                            StaticPopup_Hide("ABANDON_QUEST_WITH_ITEMS");
                            StaticPopup_Show("ABANDON_QUEST", GetAbandonQuestName());
                        end
                    </OnClick>
                    <OnEnter>
                        GameTooltip_AddNewbieTip(self, ABANDON_QUEST, 1.0, 1.0, 1.0, NEWBIE_TOOLTIP_ABANDONQUEST, 1);
                    </OnEnter>
                    <OnLeave function="GameTooltip_Hide"/>
                </Scripts>
            </Button>
            <Button parentKey="push" inherits="MagicButtonTemplate" text="SHARE_QUEST_ABBREV">
                <Size x="80" y="22"/>
                <Anchors>
                    <Anchor point="LEFT" relativeKey="$parent.abandon" relativePoint="RIGHT"/>
                </Anchors>
                <Scripts>
                    <OnClick>
                        QuestLogPushQuest()
                        PlaySound("igQuestLogOpen")
                    </OnClick>
                    <OnEnter>
                        GameTooltip_AddNewbieTip(self, SHARE_QUEST, 1.0, 1.0, 1.0, NEWBIE_TOOLTIP_SHAREQUEST, 1)
                    </OnEnter>
                    <OnLeave function="GameTooltip_Hide"/>
                </Scripts>
            </Button>
            <Button parentKey="TrackButton" inherits="MagicButtonTemplate" text="TRACK_QUEST_ABBREV">
                <Size x="80" y="22"/>
                <Anchors>
                    <Anchor point="LEFT" relativeKey="$parent.push" relativePoint="RIGHT"/>
                </Anchors>
                <Scripts>
                    <OnClick>
                        QuestGuru:ToggleWatch()
                    </OnClick>
                    <OnEnter>
                        GameTooltip_AddNewbieTip(self, TRACK_QUEST, 1.0, 1.0, 1.0, NEWBIE_TOOLTIP_TRACKQUEST, 1)
                    </OnEnter>
                    <OnLeave function="GameTooltip_Hide"/>
                </Scripts>
            </Button>


            <!-- frame with spiderwebs over left page, to show when quest log is empty -->
            <Frame parentKey="emptyLog" hidden="true">
                <Size x="305" y="340"/>
                <Anchors>
                    <Anchor point="LEFT" x="32" y="-16"/>
                </Anchors>
                <Layers>
                    <Layer level="BACKGROUND">
                        <Texture file="Interface\QuestFrame\UI-QuestLog-Empty-TopLeft">
                            <Size x="256" y="256"/>
                            <Anchors>
                                <Anchor point="TOPLEFT"/>
                            </Anchors>
                        </Texture>
                        <Texture file="Interface\QuestFrame\UI-QuestLog-Empty-BotLeft">
                            <Size x="256" y="84"/>
                            <Anchors>
                                <Anchor point="BOTTOMLEFT"/>
                            </Anchors>
                            <TexCoords left="0" right="1" top="0" bottom="0.65625"/>
                        </Texture>
                        <Texture file="Interface\QuestFrame\UI-QuestLog-Empty-TopRight">
                            <Size x="49" y="256"/>
                            <Anchors>
                                <Anchor point="TOPRIGHT"/>
                            </Anchors>
                            <TexCoords left="0" right="0.765625" top="0" bottom="1"/>
                        </Texture>
                        <Texture file="Interface\QuestFrame\UI-QuestLog-Empty-BotRight">
                            <Size x="49" y="84"/>
                            <Anchors>
                                <Anchor point="BOTTOMRIGHT"/>
                            </Anchors>
                            <TexCoords left="0" right="0.765625" top="0" bottom="0.65625"/>
                        </Texture>
                    </Layer>
                    <Layer level="ARTWORK">
                        <FontString name="QuestLogNoQuestsText" inherits="GameFontHighlight" text="QUESTLOG_NO_QUESTS_TEXT">
                            <Size x="200" y="0"/>
                            <Anchors>
                                <Anchor point="CENTER" x="-6" y="16"/>
                            </Anchors>
                        </FontString>
                    </Layer>
                </Layers>
            </Frame>
            <Frame parentKey="count" inherits="InsetFrameTemplate3">
                <Size x="120" y="20"/>
                <Anchors>
                    <Anchor point="TOPLEFT" x="132" y="-33"/>
                </Anchors>
                <Layers>
                    <Layer level="ARTWORK">
                        <FontString parentKey="text" inherits="GameFontNormalSmall" text="Quests: 0/25">
                            <Anchors>
                                <Anchor point="CENTER"/>
                            </Anchors>
                        </FontString>
                    </Layer>
                </Layers>
            </Frame>
            <Button parentKey="mapButton">
                <Size x="48" y="32"/>
                <Anchors>
                    <Anchor point="TOPRIGHT" x="-24" y="-27"/>
                </Anchors>
                <Layers>
                    <Layer level="ARTWORK">
                        <FontString name="$parentText" inherits="GameFontNormal" text="SHOW_MAP" parentKey="text">
                            <Anchors>
                                <Anchor point="RIGHT" relativePoint="LEFT" x="0" y="0"/>
                            </Anchors>
                        </FontString>
                    </Layer>
                </Layers>
                <NormalTexture file="Interface\QuestFrame\UI-QuestMap_Button">
                    <TexCoords left="0.125" right="0.875" top="0" bottom="0.5"/>
                </NormalTexture>
                <PushedTexture file="Interface\QuestFrame\UI-QuestMap_Button">
                    <TexCoords left="0.125" right="0.875" top="0.5" bottom="1.0"/>
                </PushedTexture>
                <HighlightTexture file="Interface\Buttons\ButtonHilight-Square" alphaMode="ADD">
                    <Size x="36" y="25"/>
                    <Anchors>
                        <Anchor point="RIGHT" x="-7" y="0"/>
                    </Anchors>
                </HighlightTexture>
                <Scripts>
                    <OnClick>
                        QuestGuru:ShowMap()
                    </OnClick>
                </Scripts>
            </Button>
            <!-- the actual log scrollFrame in left panel -->
            <ScrollFrame parentKey="scrollFrame" name="QuestGuruScrollFrame" inherits="HybridScrollFrameTemplate">
                <Size x="305" y="403"/>
                <Anchors>
                    <Anchor point="TOPLEFT" x="6" y="-64"/>
                </Anchors>
                <Layers>
                    <Layer level="BACKGROUND">
                        <Texture parentKey="top" file="Interface\PaperDollInfoFrame\UI-Character-ScrollBar">
                            <Size x="29" y="102"/>
                            <Anchors>
                                <Anchor point="TOPLEFT" relativePoint="TOPRIGHT" x="-6" y="5"/>
                            </Anchors>
                            <TexCoords left="0" right="0.445" top="0" bottom="0.4"/>
                        </Texture>
                        <Texture parentKey="bottom" file="Interface\PaperDollInfoFrame\UI-Character-ScrollBar">
                            <Size x="29" y="106"/>
                            <Anchors>
                                <Anchor point="BOTTOMLEFT" relativePoint="BOTTOMRIGHT" x="-6" y="-2"/>
                            </Anchors>
                            <TexCoords left="0.515625" right="0.960625" top="0" bottom="0.4140625"/>
                        </Texture>
                        <Texture file="Interface\PaperDollInfoFrame\UI-Character-ScrollBar">
                            <Size x="29" y="1"/>
                            <Anchors>
                                <Anchor point="TOP" relativeKey="$parent.top" relativePoint="BOTTOM"/>
                                <Anchor point="BOTTOM" relativeKey="$parent.bottom" relativePoint="TOP"/>
                            </Anchors>
                            <TexCoords left="0" right="0.445" top=".75" bottom="1.0"/>
                        </Texture>
                    </Layer>
                    <Layer level="BORDER">
                        <Texture parentKey="BG" file="Interface\QuestFrame\QuestBookBG">
                            <Anchors>
                                <Anchor point="TOPLEFT" x="0" y="1"/>
                                <Anchor point="BOTTOMRIGHT" x="-2" y="-2"/>
                            </Anchors>
                            <TexCoords left="0" right="0.5859375" top="0" bottom="0.65625"/>
                        </Texture>
                    </Layer>
                </Layers>
                <Frames>
                    <!-- expand/collapse all button -->
                    <Button parentKey="expandAll">
                        <Size x="64" y="32"/>
                        <Anchors>
                            <Anchor point="BOTTOMLEFT" relativePoint="TOPLEFT" x="48" y="0"/>
                        </Anchors>
                        <Layers>
                            <Layer level="BACKGROUND">
                                <Texture file="Interface\QuestFrame\UI-QuestLogSortTab-Left">
                                    <Size x="8" y="32"/>
                                    <Anchors>
                                        <Anchor point="LEFT"/>
                                    </Anchors>
                                </Texture>
                                <Texture file="Interface\QuestFrame\UI-QuestLogSortTab-Right">
                                    <Size x="8" y="32"/>
                                    <Anchors>
                                        <Anchor point="RIGHT"/>
                                    </Anchors>
                                </Texture>
                                <Texture file="Interface\QuestFrame\UI-QuestLogSortTab-Middle">
                                    <Size x="0" y="32"/>
                                    <Anchors>
                                        <Anchor point="LEFT" x="8" y="0"/>
                                        <Anchor point="RIGHT" x="-8" y="0"/>
                                    </Anchors>
                                </Texture>
                            </Layer>
                        </Layers>
                        <!-- quest title/header normalText is shifted to right 20 -->
                        <ButtonText parentKey="normalText" text="ALL">
                            <Size x="0" y="10"/>
                                <Anchors>
                                <Anchor point="LEFT" x="28" y="-4"/>
                            </Anchors>
                        </ButtonText>
                        <NormalTexture file="Interface\Buttons\UI-MinusButton-UP">
                            <Size x="16" y="16"/>
                            <Anchors>
                                <Anchor point="LEFT" x="11" y="-4"/>
                            </Anchors>
                        </NormalTexture>
                        <HighlightTexture file="Interface\Buttons\UI-PlusButton-Hilight" alphaMode="ADD">
                            <Size x="16" y="16"/>
                            <Anchors>
                                <Anchor point="LEFT" x="11" y="-4"/>
                            </Anchors>
                        </HighlightTexture>
                        <NormalFont style="GameFontNormalLeft"/>
                        <HighlightFont style="GameFontHighlightLeft"/>
                        <DisabledFont style="GameFontHighlightLeft"/>
                        <Scripts>
                            <OnClick>
                                QuestGuru:ExpandAllOnClick()
                            </OnClick>
                        </Scripts>
                    </Button>
                    <Slider name="$parentScrollBar" inherits="HybridScrollBarTemplate" parentKey="scrollBar">
                        <Anchors>
                            <Anchor point="TOPLEFT" relativePoint="TOPRIGHT" x="0" y="-13"/>
                            <Anchor point="BOTTOMLEFT" relativePoint="BOTTOMRIGHT" x="0" y="14"/>
                        </Anchors>
                        <Scripts>
                            <OnLoad>
                                local name = self:GetName();
                                _G[name.."BG"]:Hide();
                                _G[name.."Top"]:Hide();
                                _G[name.."Bottom"]:Hide();
                                _G[name.."Middle"]:Hide();
                                self.doNotHide = true;
                            </OnLoad>
                        </Scripts>
                    </Slider>
                    <Frame parentKey="highlightFrame" hidden="true">
                        <Anchors>
                            <Anchor point="TOPLEFT"/>
                            <Anchor point="BOTTOMRIGHT"/>
                        </Anchors>
                        <Layers>
                            <Layer level="ARTWORK">
                                <Texture parentKey="texture" file="Interface\QuestFrame\UI-QuestLogTitleHighlight" alphaMode="ADD"/>
                            </Layer>
                        </Layers>
                        <Scripts>
                            <OnLoad>
                                self:SetParent(nil);
                            </OnLoad>
                        </Scripts>
                    </Frame>
                </Frames>
            </ScrollFrame>
            <ScrollFrame parentKey="detail" name="QuestGuruDetailScrollFrame" inherits="QuestScrollFrameTemplate">
                <Size x="298" y="403"/> <!-- was 403 -->
                <Anchors>
                    <Anchor point="TOPRIGHT" x="-32" y="-63"/>
                </Anchors>
                <Layers>
                    <Layer level="BACKGROUND">
                        <Texture parentKey="DetailBG" file="Interface\QuestFrame\QuestBG">
                            <Anchors>
                                <Anchor point="TOPLEFT" x="-2" y="1"/>
                                <Anchor point="BOTTOMRIGHT" x="1" y="-1"/>
                            </Anchors>
                            <TexCoords left="0" right="0.5859375" top="0" bottom="0.65625"/>
                        </Texture>
                    </Layer>
                </Layers>
                <ScrollChild>
                    <Frame name="QuestGuruDetailScrollChildFrame">
                        <Size x="298" y="403"/>
                    </Frame>
                </ScrollChild>
            </ScrollFrame>


            <Frame parentKey="optionsFrame" enableMouse="true" inherits="BasicFrameTemplateWithInset" hidden="true">
                <Size x="220" y="208"/>
                <Anchors>
                    <Anchor point="BOTTOM" relativeKey="$parent.options" relativePoint="TOP" x="0" y="0"/>
                </Anchors>
                <Frames>
                    <CheckButton parentKey="UndockWindow" inherits="QuestGuruCheckButtonTemplate">
                        <Anchors>
                            <Anchor point="TOPLEFT" x="16" y="-32"/>
                        </Anchors>
                    </CheckButton>
                    <CheckButton parentKey="LockWindow" inherits="QuestGuruCheckButtonTemplate">
                        <Anchors>
                            <Anchor point="TOPLEFT" relativeKey="$parent.UndockWindow" relativePoint="BOTTOMLEFT" x="16" y="-4"/>
                        </Anchors>
                    </CheckButton>
                    <CheckButton parentKey="ShowResizeGrip" inherits="QuestGuruCheckButtonTemplate">
                        <Anchors>
                            <Anchor point="TOPLEFT" relativeKey="$parent.LockWindow" relativePoint="BOTTOMLEFT" x="-16" y="-4"/>
                        </Anchors>
                    </CheckButton>
                    <CheckButton parentKey="ShowLevels" inherits="QuestGuruCheckButtonTemplate">
                        <Anchors>
                            <Anchor point="TOPLEFT" relativeKey="$parent.ShowResizeGrip" relativePoint="BOTTOMLEFT" x="0" y="-4"/>
                        </Anchors>
                    </CheckButton>
                    <CheckButton parentKey="ShowTooltips" inherits="QuestGuruCheckButtonTemplate">
                        <Anchors>
                            <Anchor point="TOPLEFT" relativeKey="$parent.ShowLevels" relativePoint="BOTTOMLEFT" x="0" y="-4"/>
                        </Anchors>
                    </CheckButton>
                    <CheckButton parentKey="SolidBackground" inherits="QuestGuruCheckButtonTemplate">
                        <Anchors>
                            <Anchor point="TOPLEFT" relativeKey="$parent.ShowTooltips" relativePoint="BOTTOMLEFT" x="0" y="-4"/>
                        </Anchors>
                    </CheckButton>
                </Frames>
            </Frame>

        </Frames>
        <Scripts>
            <OnLoad>
                self:RegisterEvent("PLAYER_LOGIN")
            </OnLoad>
            <OnEvent>
                self.OnEvent(self,event)
            </OnEvent>
            <OnShow>
                self.OnShow(self)
                PlaySound("igQuestLogOpen")
            </OnShow>
            <OnHide>
                self.OnHide(self)
                PlaySound("igQuestLogClose")
            </OnHide>
            <OnMouseDown>
                self:StartMoving()
            </OnMouseDown>
            <OnMouseUp>
                self:StopMovingOrSizing()
            </OnMouseUp>
        </Scripts>
    </Frame>
</Ui>

Thank you

Phanx 10-12-16 07:15 PM

The immediate parent of your button is QuestGuru, so the globally accessible path to your button is QuestGuru.TrackButton:

/run QuestGuru.TrackButton:SetText("Test")

Lazare 10-14-16 05:07 AM

Trying the above gave this error:
Code:

1x [string "QuestGuru.TrackButton:SetText("Test")"]:1: attempt to index field 'TrackButton' (a nil value)
[string "QuestGuru.TrackButton:SetText("Test")"]:1: in main chunk
[C]: in function `RunScript'
FrameXML\ChatFrame.lua:2051: in function `?'
FrameXML\ChatFrame.lua:4332: in function `ChatEdit_ParseText'
FrameXML\ChatFrame.lua:4000: in function `ChatEdit_SendText'
FrameXML\ChatFrame.lua:4036: in function `ChatEdit_OnEnterPressed'
[string "*:OnEnterPressed"]:1: in function <[string "*:OnEnterPressed"]:1>


Locals:
(*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to index field 'TrackButton' (a nil value)"


Phanx 10-17-16 05:09 PM

This is from the XML you posted:

Code:

<Frame name="QuestGuru" parent="UIParent" ...>
    ...
    <Frames>
        ...
        <Button parentKey="TrackButton" inherits="MagicButtonTemplate" text="TRACK_QUEST_ABBREV">

Based on that, the button's parent is the frame with the global name "QuestGuru" and the button's parentKey is "TrackButton", which means it's available as "QuestGuru.TrackButton".

The only ways that "QuestGuru.TrackButton" can be nil are:

1. The code you posted is not your real code.

2. Some other code (that you didn't post) overrides the "QuestGuru" global with some other object that isn't the frame created by your XML, so there's no longer any global reference to the frame or anything (like the button) attached to it.

Again, this is why you should post your entire, actual code when you're asking for help. It doesn't matter if it's 50 lines or 50,000,000 lines -- we're not going to read through every line, we're going to search for specific parts that are related to the issue at hand. Without being able to do that, all we can do is throw out random guesses that may or may not be useful.

The only difference between 50 lines and 50,000,000 lines is that you should not embed the latter in a forum post; use pastebin or gist for longer pieces of code.

Lazare 10-25-16 08:08 PM

Thanks for all of your help, especially Phanx. They code I posted above was directly from my addon. Next time I will postman or github them. For any wanting to know how I fixed it, posting below:This first section checks whether a quest is tracked and if so, untracked it. or just the opposite if is not tracked.
Code:

function qgc:ToggleWatch(index)
        if not index then
                index = GetQuestLogSelection()
        end
        if index>0 then
                if IsQuestWatched(index) then -- already watched, remove from watch
                        RemoveQuestWatch(index)
                        QuestGuru.Track:SetText("Track")
                else -- not watched, see if there's room to add, add if so
                        if GetNumQuestWatches() >= MAX_WATCHABLE_QUESTS then
                                UIErrorsFrame:AddMessage(format(QUEST_WATCH_TOO_MANY,MAX_WATCHABLE_QUESTS),1,0.1,0.1,1)
                        else
                                AddQuestWatch(index)
                                QuestGuru.Track:SetText("UnTrack")
                        end
                end
        end
end


and second section changes the button to Track/UnTrack depending if the quest is tracked or not:
Code:

function qgc:SelectQuestIndex(index)


        SelectQuestLogEntry(index)


        StaticPopup_Hide("ABANDON_QUEST")
        StaticPopup_Hide("ABANDON_QUEST_WITH_ITEMS")
        SetAbandonQuest()


        if ( index == 0 ) then
                qgc.selectedIndex = nil
                QuestGuruDetailScrollFrame:Hide()
        elseif index>0 and index<=GetNumQuestLogEntries() and not select(4,GetQuestLogTitle(index)) then
                QuestGuruDetailScrollFrame:Show()
                QuestInfo_Display(QUEST_TEMPLATE_LOG, QuestGuruDetailScrollChildFrame)
                QuestGuruDetailScrollFrameScrollBar:SetValue(0) -- scroll to top
        end
                if IsQuestWatched(index) then -- already watched, remove from watch
                        QuestGuru.Track:SetText("UnTrack")
                else -- not watched, see if there's room to add, add if so
                        QuestGuru.Track:SetText("Track")
                end
       
        qgc:UpdateLogList()
end



I thought this might be handy for others that may want a button to change depending on what is needed.


Cheers!

rowaasr13 11-01-16 11:16 PM

Quote:

Originally Posted by Phanx (Post 319665)
The difference is that SetFormattedText shifts the string.format operation over into C code, where it's (presumably) faster than running it in Lua. Unless you're doing it a million times in a row, though, you'll never notice the difference, so the main reason to use SetFormattedText is that it makes your code less verbose and more readable.

I believe the real difference is that resulting formatted string doesn't enter Lua's hashed pool, thus not only providing noticeable speed up, but also saving you from tons of throwaway strings for GC to clean up later. This could be trivially tested by :SetText(format("%s", GeTtime)) in OnUpdate and watching garbage counter grow vs. SetFormattedText. I'll try it later to confirm (unless I'll forget about that).

rowaasr13 11-03-16 12:24 PM

Just confirmed this.

Lua Code:
  1. /run for idx = 1, 500000 do MountJournal.SummonRandomFavoriteButton.spellname:SetText(string.format("%d %d", idx, idx)) end
+10 Mb addon memory.

Lua Code:
  1. /run for idx = 1, 500000 do MountJournal.SummonRandomFavoriteButton.spellname:SetFormattedText("%d %d", idx, idx) end
No changes to addon memory.


All times are GMT -6. The time now is 08:11 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI