Quantcast [LUA] What have I done wrong - WoWInterface
Thread Tools Display Modes
11-25-14, 05:10 PM   #1
saxitoxin
A Wyrmkin Dreamwalker
 
saxitoxin's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 59
[LUA] What have I done wrong

I have made a xp/rep bar, but I have made a mistake that I can't seem to find out what as my coding skills is still very basic

What is happening is that when I alt+z to hide everything my bar is still showing. same goes for when I use my afk camera addon

if someone could help me out I would be very happy

Lua Code:
  1. ------------------------------------------------------
  2. -- VARIABLES
  3. ------------------------------------------------------
  4. local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[(select(2, UnitClass("player")))]
  5. local width = 500
  6. local height = 6
  7. local point = "BOTTOM"
  8. local posx = 0
  9. local posy = 16
  10. local strata = "MEDIUM"
  11. local statusbartex = "Interface\\AddOns\\AdvancementBar\\statusbar.tga"
  12. local circle = "Interface\\AddOns\\AdvancementBar\\orb.tga"
  13. local gloss = "Interface\\AddOns\\AdvancementBar\\gloss.tga"
  14.  
  15. --number format func
  16. local SVal = function(val)
  17.     if val > 1E10 then
  18.         return (floor(val/1E9)).."b"
  19.     elseif val > 1E9 then
  20.         return (floor((val/1E9)*10)/10).."b"
  21.     elseif val > 1E7 then
  22.         return (floor(val/1E6)).."m"
  23.     elseif val > 1E6 then
  24.         return (floor((val/1E6)*10)/10).."m"
  25.     elseif val > 1E5 then
  26.         return (floor(val/1E3)).."k"
  27.     elseif val >= 1E3 then
  28.         return (floor(val/1E3)) .. (" %03d"):format(val % 1E3)
  29.     else
  30.         return val
  31.     end
  32. end
  33.  
  34. ------------------------------------------------------
  35. -- UPDATING THE BAR
  36. ------------------------------------------------------
  37.  
  38. local updateOrb = function(statusbar,value)
  39.     local min, max = statusbar:GetMinMaxValues()
  40.     local per = 0
  41.     if max > 0 then per = value/max*100 end
  42.     local offset = statusbar:GetWidth()-(per*statusbar:GetWidth()/100)
  43.     orba:SetPoint("CENTER",statusbar,"RIGHT",-offset,0)
  44. local orbr, orbg, orbb = statusbar:GetStatusBarColor()
  45.     orbt:SetVertexColor(orbr,orbg,orbb)
  46. end
  47.  
  48. local function rbar_ReSetValue(rxp, xp, mxp)
  49.     if rxp then
  50.         if rxp+xp >= mxp then
  51.             restbar:SetValue(mxp)
  52.         else
  53.             restbar:SetValue(rxp+xp)
  54.         end
  55.     else
  56.         restbar:SetValue(0)
  57.     end
  58. end
  59.  
  60. --showxp
  61. local function bf_ShowXP(rxp, xp, mxp)
  62.     bgt:SetVertexColor(color.r,color.g,color.b, 0.2)
  63.     statusbar:SetStatusBarColor(color.r,color.g,color.b, 0.85)
  64.     statusbar:SetMinMaxValues(0,mxp)
  65.     statusbar:SetValue(xp)
  66.     text:SetText(format(SVal(xp)).." / "..format(SVal(mxp)).." / "..floor((xp/mxp)*1000)/10 .." %")
  67.     restbar:SetMinMaxValues(0,mxp)
  68.     rbar_ReSetValue(rxp, xp, mxp)
  69.     end
  70.  
  71. --showrep
  72. local function bf_ShowRep()
  73.     name, standing, minrep, maxrep, value = GetWatchedFactionInfo()
  74.     if name then
  75.         bgt:SetVertexColor(FACTION_BAR_COLORS[standing].r, FACTION_BAR_COLORS[standing].g, FACTION_BAR_COLORS[standing].b, 0.2)
  76.         statusbar:SetStatusBarColor(FACTION_BAR_COLORS[standing].r, FACTION_BAR_COLORS[standing].g, FACTION_BAR_COLORS[standing].b, 0.85)
  77.         statusbar:SetMinMaxValues(0,maxrep)
  78.         statusbar:SetValue(value)
  79.         text:SetText("")
  80.         restbar:SetValue(0)
  81.         local orbr, orbg, orbb = statusbar:GetStatusBarColor()
  82.         orbt:SetVertexColor(orbr,orbg,orbb)
  83.     else
  84.         mxp = UnitXPMax("player")
  85.         xp = UnitXP("player")
  86.         rxp = GetXPExhaustion()
  87.         bf_ShowXP(rxp, xp, mxp)
  88.     end
  89. end
  90.  
  91. ------------------------------------------------------
  92. -- CREATE STATUSBAR
  93. ------------------------------------------------------
  94.  
  95. local bg = CreateFrame("Frame", UIParent)
  96. bg:SetSize(width, height)
  97. bg:SetPoint(point, posx, posy)
  98. local bgtexture = bg:CreateTexture(nil,"OVERLAY",nil,0)
  99. bgtexture:SetAllPoints()
  100. bgtexture:SetTexture(statusbartex)
  101. bgtexture:SetVertexColor(color.r,color.g,color.b,0.2)
  102. bgt = bgtexture
  103.  
  104. local sbar = CreateFrame("StatusBar", nil, bg)
  105. sbar:SetFrameLevel(2)
  106. sbar:SetFrameStrata(strata)
  107. sbar:SetSize(bg:GetSize())
  108. sbar:SetStatusBarTexture(statusbartex)
  109. sbar:SetStatusBarColor(color.r,color.g,color.b,0.8)
  110. sbar:SetPoint("CENTER")
  111. sbar:SetMinMaxValues(0,100)
  112. sbar:SetValue(0)
  113. sbar:SetScript("OnValueChanged", updateOrb)
  114. statusbar = sbar
  115.  
  116. local rbar = CreateFrame("StatusBar", nil, sbar)
  117. rbar:SetFrameLevel(1)
  118. rbar:SetFrameStrata(strata)
  119. rbar:SetSize(bg:GetSize())
  120. rbar:SetStatusBarTexture(statusbartex)
  121. rbar:SetStatusBarColor(0.6,0.6,0.6,0.6)
  122. rbar:SetPoint("CENTER")
  123. rbar:SetMinMaxValues(0,100)
  124. rbar:SetValue(0)
  125. restbar = rbar
  126.  
  127. local orb = CreateFrame("Frame", nil, sbar)
  128. orb:SetFrameLevel(3)
  129. orb:SetSize(height*1.5, height*1.5)
  130. local orbtexture = orb:CreateTexture(nil,"OVERLAY",nil,0)
  131. local orbr, orbg, orbb = sbar:GetStatusBarColor()
  132. orbtexture:SetVertexColor(orbr,orbg,orbb)
  133. orbtexture:SetTexture(circle)
  134. orbtexture:SetAllPoints()
  135.  
  136. orbgloss = orb:CreateTexture(nil,"OVERLAY",nil,7)
  137. orbgloss:SetTexture(gloss)
  138. orbgloss:SetAllPoints()
  139.  
  140. orbt = orbtexture
  141. orba = orb
  142. orb:EnableMouse(true)
  143.  
  144. orb:RegisterEvent("PLAYER_XP_UPDATE")
  145. orb:RegisterEvent("PLAYER_LEVEL_UP")
  146. orb:RegisterEvent("PLAYER_ENTERING_WORLD")
  147. orb:RegisterEvent("UPDATE_FACTION")
  148. orb:RegisterEvent("MODIFIER_STATE_CHANGED")
  149.  
  150. textframe = sbar:CreateFontString(nil, "OVERLAY")
  151. textframe:SetFont(STANDARD_TEXT_FONT, 7, "THINOUTLINE")
  152. textframe:SetPoint("CENTER", 0, 0)
  153. textframe:SetTextColor(color.r,color.g,color.b)
  154. textframe:SetText("XP BAR")
  155. text = textframe
  156.  
  157.  
  158. orb:SetScript("OnEvent", function(this, event, arg1, arg2, arg3, arg4, ...)
  159.     mxp = UnitXPMax("player")
  160.     xp = UnitXP("player")
  161.     rxp = GetXPExhaustion()
  162.    
  163.     if event == "PLAYER_ENTERING_WORLD" then
  164.         if UnitLevel("player") == MAX_PLAYER_LEVEL then
  165.             bf_ShowRep()
  166.         else
  167.             bf_ShowXP(rxp, xp, mxp)
  168.         end
  169.     elseif event == "PLAYER_XP_UPDATE" and arg1 == "player" then
  170.         statusbar:SetValue(xp)
  171.         rbar_ReSetValue(rxp, xp, mxp)
  172.     elseif event == "PLAYER_LEVEL_UP" then
  173.         if UnitLevel("player") == MAX_PLAYER_LEVEL then
  174.             bf_ShowRep()
  175.         else
  176.             bf_ShowXP(rxp, xp, mxp)
  177.         end
  178.     elseif event == "MODIFIER_STATE_CHANGED" then
  179.         if arg1 == "LCTRL" or arg1 == "RCTRL" then
  180.             if arg2 == 1 then
  181.                 bf_ShowRep()
  182.             elseif arg2 == 0 and UnitLevel("player") ~= MAX_PLAYER_LEVEL then
  183.                 bf_ShowXP(rxp, xp, mxp)
  184.             end
  185.         end
  186.     elseif event == "UPDATE_FACTION" then
  187.         if UnitLevel("player") == MAX_PLAYER_LEVEL then
  188.             bf_ShowRep()
  189.         end
  190.     end
  191. end)
  192.  
  193. orb:SetScript("OnEnter", function()
  194.  
  195. if UnitAffectingCombat('player') then
  196. else
  197.  
  198.     local mxp = UnitXPMax("player")
  199.     local xp = UnitXP("player")
  200.     local nxp = mxp - xp
  201.     local rxp = GetXPExhaustion()
  202.     local name, standing, minrep, maxrep, value = GetWatchedFactionInfo()
  203.    
  204.     GameTooltip:SetOwner(UIParent, "ANCHOR_CURSOR")
  205.     if UnitLevel("player") ~= MAX_PLAYER_LEVEL then
  206.         GameTooltip:AddLine("exp Bar")
  207.         GameTooltip:AddDoubleLine(COMBAT_XP_GAIN, format(SVal(xp)).."|cffffd100/|r"..format(SVal(mxp)).." |cffffd100/|r "..floor((xp/mxp)*1000)/10 .."%",NORMAL_FONT_COLOR.r,NORMAL_FONT_COLOR.g,NORMAL_FONT_COLOR.b,1,1,1)
  208.         GameTooltip:AddDoubleLine(NEED, format(SVal(nxp)).." |cffffd100/|r "..floor((nxp/mxp)*1000)/10 .."%",NORMAL_FONT_COLOR.r,NORMAL_FONT_COLOR.g,NORMAL_FONT_COLOR.b,1,1,1)
  209.         if rxp then
  210.             GameTooltip:AddDoubleLine(TUTORIAL_TITLE26, format(SVal(rxp)) .." |cffffd100/|r ".. floor((rxp/mxp)*1000)/10 .."%", NORMAL_FONT_COLOR.r,NORMAL_FONT_COLOR.g,NORMAL_FONT_COLOR.b,1,1,1)
  211.         end
  212.         if name then
  213.             GameTooltip:AddLine(" ")
  214.         end
  215.     else
  216.         GameTooltip:AddLine("rep Bar")
  217.     end
  218.     if name then
  219.         GameTooltip:AddDoubleLine(FACTION, name, NORMAL_FONT_COLOR.r,NORMAL_FONT_COLOR.g,NORMAL_FONT_COLOR.b,1,1,1)
  220.         GameTooltip:AddDoubleLine(STANDING, getglobal("FACTION_STANDING_LABEL"..standing), NORMAL_FONT_COLOR.r,NORMAL_FONT_COLOR.g,NORMAL_FONT_COLOR.b,FACTION_BAR_COLORS[standing].r, FACTION_BAR_COLORS[standing].g, FACTION_BAR_COLORS[standing].b)
  221.         GameTooltip:AddDoubleLine(REPUTATION, value-minrep .."|cffffd100/|r"..maxrep-minrep.." |cffffd100/|r "..floor((value-minrep)/(maxrep-minrep)*1000)/10 .."%", NORMAL_FONT_COLOR.r,NORMAL_FONT_COLOR.g,NORMAL_FONT_COLOR.b,1,1,1)
  222.         nrep = maxrep - value
  223.         GameTooltip:AddDoubleLine(NEED, format(SVal(nrep)).." |cffffd100/|r "..floor((nrep/maxrep)*1000)/10 .."%",NORMAL_FONT_COLOR.r,NORMAL_FONT_COLOR.g,NORMAL_FONT_COLOR.b,1,1,1)
  224.     end
  225.     GameTooltip:Show()
  226. end
  227. end)
  228.  
  229. orb:SetScript("OnLeave", function()
  230.     GameTooltip:Hide()
  231. end)
  Reply With Quote
11-25-14, 05:26 PM   #2
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 329
I'm pretty sure alt+z hides the UIParent.

The only thing I'm aware of that sticks around is say the FPS indicator (ctrl+f).

Screenshot or it didn't happen?
  Reply With Quote
11-25-14, 05:35 PM   #3
saxitoxin
A Wyrmkin Dreamwalker
 
saxitoxin's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 59
image showing what I mean
  Reply With Quote
11-25-14, 06:07 PM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,059
local bg = CreateFrame("Frame", UIParent) <- this isn't creating a frame with UIParent as the parent, it's trying to name it whatever the value of UIParent is.
  Reply With Quote
11-25-14, 06:52 PM   #5
Eternal_Lynx
An Aku'mai Servant
 
Eternal_Lynx's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 31
API CreateFrame:
Lua Code:
  1. newFrame = CreateFrame("frameType"[, "frameName"[, parentFrame[, "inheritsFrame"]]]);

The second argument is frame name not frame parent.
And if a visible frame is not a child of UIParent, it won't change it's visibility with UIParent(Alt+Z).

try
Lua Code:
  1. local bg = CreateFrame("Frame", nil, UIParent);

or
Lua Code:
  1. local bg = CreateFrame('Frame', nil, UIParent)

whatever...
__________________
Moo'. Are you happy now?

Last edited by Eternal_Lynx : 11-26-14 at 06:43 AM. Reason: Really? Reason?
  Reply With Quote
11-25-14, 11:32 PM   #6
saxitoxin
A Wyrmkin Dreamwalker
 
saxitoxin's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 59
Thanks you

Thank you for your help people

just another question, why use the semicolon?
  Reply With Quote
11-25-14, 11:50 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by saxitoxin View Post
just another question, why use the semicolon?
Because they're used to programming in some language where semicolons are actually useful/required, and since Lua lets them include such pointless eyesores in their Lua code, they just keep using them.
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
  Reply With Quote
11-26-14, 04:53 AM   #8
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Originally Posted by saxitoxin View Post
Thank you for your help people

just another question, why use the semicolon?
That is, they are not required and it's purely a matter of personal preference. :P
__________________
Grab your sword and fight the Horde!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » [LUA] What have I done wrong

Thread Tools
Display Modes

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