Thread Tools Display Modes
05-18-09, 09:55 PM   #1
Samsan
An Aku'mai Servant
 
Samsan's Avatar
Join Date: May 2009
Posts: 33
Unhappy Virtual buttonText Error

Hey all, I'm rather new to lua and am trying to figure out what went wrong with the scrollframe. I managed to get data to display long enough to set column text alignments, however not all of the factions showed up, neither did the header text and scroll didn't scroll and then I received the error ..

Message: ..\AddOns\MyMod\MyMod.lua line 128:
attempt to index local 'buttonText' (a nil value)
Any help at all would be appreciated...thx
Code:
function DWMPackRepFrame_OnLoad(self)

    --oldReputationFrame_Update = ReputationFrame_Update;
    --ReputationFrame_Update = DWMPackRepFrame_Update;

    local DWMPackRepFrame_UpdateFrame

	self:RegisterEvent("UPDATE_FACTION");
	-- Initialize max player level
	MAX_PLAYER_LEVEL = MAX_PLAYER_LEVEL_TABLE[GetAccountExpansionLevel()];

    local _, race = UnitRace("player")
end

-- Round function for percentages
function round(x)
	return floor(x + 0.5)
end

function DWMPackRepScrollFrame_Update(self)

    local numFactions = GetNumFactions();
    local numFactions, totalCount = GetNumFactions();
    local line, name, _, standingID, bottomValue, topValue, earnedValue, _, _, isHeader, _, hasRep, isWatched, _;
--~ 	local name, description, standingID, barMin, barMax, barValue, atWarWith, canToggleAtWar, isHeader, isCollapsed, hasRep, isWatched, isChild = GetFactionInfo(factionIndex);
    local button, buttonText, FactionName, FactionItems, FactionStanding, FactionPercent, FactionSession, FactionNumbers, FactionRepToGo;
    local dwmpackrepIndex, factionIndex;   
    local columnTable;
	local dwmpackrepOffset = FauxScrollFrame_GetOffset(DWMPackRepScrollFrame);
    local color = DWMP_FACTION_BAR_COLORS[standingID];

	local showScrollBar = nil;
        if ( numFactions > DWMP_NUM_FACTIONS_DISPLAYED ) then
		showScrollBar = 1;
	end
	local displayedText = "";
--~ 	if ( numFactions > DWMP_NUM_FACTIONS_DISPLAYED ) then
--~ 		displayedText = format(button.buttonText);
--~ 	end
    
	local i;

    for i = 1, GetNumFactions() do
        name, description, standingID, barMin, barMax, barValue, atWarWith, canToggleAtWar, isHeader, isCollapsed, hasRep, isWatched, isChild= GetFactionInfo(i);
		dwmpackrepIndex = dwmpackrepOffset + i;
		button = getglobal("DWMPackRepEntryButton"..i);
        button.dwmpackrepIndex = dwmpackrepIndex;
--~         FactionName, FactionItems, FactionStanding, FactionPercent, FactionSession, FactionNumbers, FactionRepToGo = GetText(dwmpackrepIndex);
		columnTable = { FactionName, FactionItems, FactionStanding, FactionPercent, FactionSession, FactionNumbers, FactionRepToGo};
        if isHeader then
            buttonText = getglobal("DWMPackRepEntryButton"..i.."FactionName");
            buttonText:SetText(name);
            return;
            end
          if isHeader == 1 and hasRep == nil and barValue ~= 0 then
            hasRep = 1
            if description == '' then
                description = GRAY_FONT_COLOR_CODE .. '(hidden reputation)' .. FONT_COLOR_CODE_CLOSE
            end
        end
        return name, description, standingID, barMin, barMax, barValue, atWarWith, canToggleAtWar, isHeader, isCollapsed, hasRep;
        end
        buttonText = getglobal("DWMPackRepEntryButton"..i.."FactionName");
        buttonText:SetText(name);
        buttonText = getglobal("DWMPackRepEntryButton"..i.."FactionItems");
        buttonText:SetText("items");
        buttonText = getglobal("DWMPackRepEntryButton"..i.."FactionStanding");
        buttonText:SetText(standingText);
        buttonText = getglobal("DWMPackRepEntryButton"..i.."FactionPercent");
        buttonText:SetText(math.floor( (earnedValue-bottomValue)/(topValue-bottomValue) * 100).."% ");
        buttonText = getglobal("DWMPackRepEntryButton"..i.."FactionSession");
        buttonText:SetText("session");
        buttonText = getglobal("DWMPackRepEntryButton"..i.."FactionNumbers");
        buttonText:SetText(earnedValue-bottomValue.."/"..topValue-bottomValue);
        buttonText = getglobal("DWMPackRepEntryButton"..i.."FactionRepToGo");
        buttonText:SetText(topValue-earnedValue); 
--~ end

    for i = 1, NumFactions() do
        name, description, standingID, barMin, barMax, barValue, atWarWith, canToggleAtWar, isHeader, isCollapsed, hasRep, isWatched, isChild= GetFactionInfo(i);
        if not isHeader then        
		buttonText = getglobal("DWMPackRepEntryButton"..i.."FactionName");
		buttonText:SetText(name);
		buttonText = getglobal("DWMPackRepEntryButton"..i.."FactionItems");
		buttonText:SetText("items");
		buttonText = getglobal("DWMPackRepEntryButton"..i.."FactionStanding");
		buttonText:SetText(standingText);
		buttonText = getglobal("DWMPackRepEntryButton"..i.."FactionPercent");
		buttonText:SetText(math.floor( (earnedValue-bottomValue)/(topValue-bottomValue) * 100).."% ");
		buttonText = getglobal("DWMPackRepEntryButton"..i.."FactionSession");
		buttonText:SetText("session");
		buttonText = getglobal("DWMPackRepEntryButton"..i.."FactionNumbers");
		buttonText:SetText(earnedValue-bottomValue.."/"..topValue-bottomValue);
		buttonText = getglobal("DWMPackRepEntryButton"..i.."FactionRepToGo");
		buttonText:SetText(topValue-earnedValue); 
        end
        
        standingText = ""
            if standingID == 1 then
            standingText = "|cff8b0000Hated|r";
        elseif standingID == 2 then
            standingText = "|cffff1919Hostile|r";
        elseif standingID == 3 then
            standingText = "|cffff8C00Unfriendly|r";
        elseif standingID == 4 then
            standingText = "|cffc0c0c0Neutral|r";
        elseif standingID == 5 then
            standingText = "|cffffffffFriendly|r";
        elseif standingID == 6 then
            standingText = "|cff19ff19Honored|r";
        elseif standingID == 7 then
            standingText = "|cff4169e1Revered|r";
        elseif standingID == 8 then
            standingText = "|cff9932ccExalted|r";
        end
        DWMPackRepScrollFrame:Show();  
      end
  end

function DWMPackRepFrame_OnEvent(self, event, ...)
	if ( event == "UPDATE_FACTION" ) then
		if ( self:IsVisible() ) then
			DWMPackRepFrame_Update();
  		end
	end
end

function DWMPackRepFrame_OnShow(self)

	if ( DWMPackRepFrame:IsShown() ) then
		DWMPackRepFrame_Update(); 
        DWMPackRepScrollFrame_Update(self);
    end
end
and the xml button

Code:
   <Button name="DWMPackRepEntryButtonTemplate" virtual="true">
      <Size>
         <AbsDimension x="670" y="22" />
      </Size>
        <Layers>
			<Layer level="BACKGROUND">
                <FontString name="|cff19ff19$parentFactionName|r" inherits="GameFontNormal" justifyH="LEFT">
					<Size>
						<AbsDimension x="140" y="14"/>
					</Size>
					<Anchors>
						<Anchor point="TOPLEFT">
							<Offset>
								<AbsDimension x="7" y="0"/>
							</Offset>
						</Anchor>
					</Anchors>
				</FontString>
				<FontString name="|cffff8C00$parentFactionItems|r" inherits="GameFontHighlight" justifyH="CENTER">
					<Size>
						<AbsDimension x="50" y="14"/>
					</Size>
					<Anchors>
						<Anchor point="TOPLEFT" relativeTo="$parentFactionName" relativePoint="TOPRIGHT">
							<Offset>
								<AbsDimension x="5" y="0"/>
							</Offset>
						</Anchor>
					</Anchors>
				</FontString>
				<FontString name="$parentFactionStanding" inherits="GameFontHighlight" justifyH="LEFT">
					<Size>
						<AbsDimension x="80" y="14"/>
					</Size>
					<Anchors>
						<Anchor point="TOPLEFT" relativeTo="$parentFactionItems" relativePoint="TOPRIGHT">
							<Offset>
								<AbsDimension x="25" y="0"/>
							</Offset>
						</Anchor>
					</Anchors>
				</FontString>
				<FontString name="$parentFactionPercent" inherits="GameFontHighlight" justifyH="RIGHT">
					<Size>
						<AbsDimension x="47" y="14"/>
					</Size>
					<Anchors>
						<Anchor point="TOPLEFT" relativeTo="$parentFactionStanding" relativePoint="TOPRIGHT">
							<Offset>
								<AbsDimension x="10" y="0"/>
							</Offset>
						</Anchor>
					</Anchors>
				</FontString>
				<FontString name="$parentFactionSession" inherits="GameFontHighlight" justifyH="CENTER">
					<Size>
						<AbsDimension x="55" y="14"/>
					</Size>
					<Anchors>
						<Anchor point="TOPLEFT" relativeTo="$parentFactionPercent" relativePoint="TOPRIGHT">
							<Offset>
								<AbsDimension x="19" y="0"/>
							</Offset>
						</Anchor>
					</Anchors>
				</FontString>
				<FontString name="$parentFactionNumbers" inherits="GameFontHighlight" justifyH="RIGHT">
					<Size>
						<AbsDimension x="90" y="14"/>
					</Size>
					<Anchors>
						<Anchor point="TOPLEFT" relativeTo="$parentFactionSession" relativePoint="TOPRIGHT">
							<Offset>
								<AbsDimension x="37" y="0"/>
							</Offset>
						</Anchor>
					</Anchors>
				</FontString>
				<FontString name="$parentFactionRepToGo" inherits="GameFontHighlight" justifyH="RIGHT">
					<Size>
						<AbsDimension x="60" y="14"/>
					</Size>
					<Anchors>
						<Anchor point="TOPLEFT" relativeTo="$parentFactionNumbers" relativePoint="TOPRIGHT">
							<Offset>
								<AbsDimension x="18" y="0"/>
							</Offset>
						</Anchor>
					</Anchors>
				</FontString>
			</Layer>
		</Layers>
        <Scripts>
           <OnLoad>
				self:SetFrameLevel(self:GetFrameLevel() + 1);
			</OnLoad>
        </Scripts>
  </Button>
Any help would be most appreciated.

Last edited by Samsan : 05-26-09 at 02:47 AM. Reason: Just updating it.
  Reply With Quote
05-26-09, 02:49 AM   #2
Samsan
An Aku'mai Servant
 
Samsan's Avatar
Join Date: May 2009
Posts: 33
Question Button Text Error

This is very frustrating.....
__________________
To give is to receive so the more that you give the more that you receive.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Virtual buttonText Error


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off