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:
Thanks in advance for any help on this. Cheers! |
TRACK_QUEST_ABBREV is a variable which holds a string. :SetText and :SetFormattedText are methods for a FontString object.
|
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) 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:
... 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:
SetFormattedText is a "shortcut" to calling string.format and SetText; these do the same thing: Lua Code:
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. |
The xml code is below
Code:
<Button parentKey="TrackButton" inherits="MagicButtonTemplate" text="TRACK_QUEST_ABBREV"> lua Code:
Blizzards coding from the Map/Quest is: lua Code:
Cheers |
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.
|
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/ |
The immediate parent of your button is QuestGuru, so the globally accessible path to your button is QuestGuru.TrackButton:
/run QuestGuru.TrackButton:SetText("Test") |
Trying the above gave this error:
Code:
1x [string "QuestGuru.TrackButton:SetText("Test")"]:1: attempt to index field 'TrackButton' (a nil value) |
This is from the XML you posted:
Code:
<Frame name="QuestGuru" parent="UIParent" ...> 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. |
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) and second section changes the button to Track/UnTrack depending if the quest is tracked or not: Code:
function qgc:SelectQuestIndex(index) I thought this might be handy for others that may want a button to change depending on what is needed. Cheers! |
Quote:
|
Just confirmed this.
Lua Code:
Lua Code:
|
All times are GMT -6. The time now is 08:04 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI