Thread Tools Display Modes
09-25-17, 06:54 AM   #1
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
code integration

trying to work some code in, could i get a hand

trying to shorten the numbers in my artifact bar adding this code in but not sure how to name it all to my own code

here is my code

Lua Code:
  1. local AXP_COLOR = { r = 0.6, g = 0.2, b = 0.1 }
  2. --Lets set up the Frame
  3. local derArtifactBar = CreateFrame("Statusbar", "derArtifactBar",artifactFrame)
  4.     derArtifactBar:SetPoint("CENTER", 0, 0)
  5.     derArtifactBar:SetHeight(18)
  6.     derArtifactBar:SetWidth(artifactFrame:GetWidth() * .968)
  7.     derArtifactBar:SetStatusBarTexture("Interface\\AddOns\\_Deranjata\\media\\cast\\Waterline")
  8.     derArtifactBar:SetStatusBarColor(AXP_COLOR.r, AXP_COLOR.g, AXP_COLOR.b, 0.5)
  9.     derArtifactBar:SetBackdrop({
  10.     bgFile =  "Interface\\AddOns\\_Deranjata\\media\\cast\\Lines",
  11.     insets = { left = 1, right = 1, top = 1, bottom = 1 }
  12.     })
  13. derArtifactBar:SetBackdropColor(0.1, 0.1, 0.1)
  14. derArtifactBar:SetBackdropBorderColor(0.6, 0.6, 0.6)
  15. --lets clear any text then set out centerpoint
  16. derArtifactBar.Text=derArtifactBar:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  17. derArtifactBar.Text:SetPoint("CENTER")      
  18.  
  19. --Registering out watched events
  20. derArtifactBar:RegisterEvent("PLAYER_ENTERING_WORLD")
  21. derArtifactBar:RegisterEvent("ARTIFACT_XP_UPDATE")
  22. derArtifactBar:RegisterEvent("UNIT_INVENTORY_CHANGED")
  23.  
  24. -- now lets update the position and text on the bar so we can always have accurate info
  25. derArtifactBar:SetScript("OnEvent", function(self, event, ...)
  26.     if not HasArtifactEquipped() then self:Hide() return end
  27.     self:Show()
  28.     local itemID, altItemID, name, icon, xp, pointsSpent, quality, artifactAppearanceID, appearanceModID, itemAppearanceID, altItemAppearanceID, altOnTop, artifactTier = C_ArtifactUI.GetEquippedArtifactInfo()
  29.     local numPoints, artifactXP, xpForNextPoint = MainMenuBar_GetNumArtifactTraitsPurchasableFromXP(pointsSpent, xp, artifactTier)
  30.     self:SetMinMaxValues(0,xpForNextPoint)
  31.     self:SetValue(artifactXP)
  32.  
  33.    
  34.    local bugFix = artifactXP/xpForNextPoint
  35.     self.Text:SetFormattedText("Current %d +%d Points",bugFix,numPoints)
  36.  
  37.  
  38. -- self.Text:SetFormattedText("Artifact XP: %d / %d       +%d Points",artifactXP,xpForNextPoint,numPoints)
  39. end)

want to add this in to replace line

local bugFix = artifactXP/xpForNextPoint
self.Text:SetFormattedText("Current %d +%d Points",bugFix,numPoints)

Lua Code:
  1. local function ReadableNumber(num, places)
  2.     local ret
  3.     local placeValue = ("%%.%df"):format(places or 0)
  4.     if not num then
  5.         return 0
  6.     elseif num >= 1000000000000 then
  7.         ret = placeValue:format(num / 1000000000000) .. " Tril" -- trillion
  8.     elseif num >= 1000000000 then
  9.         ret = placeValue:format(num / 1000000000) .. " Bil" -- billion
  10.     elseif num >= 1000000 then
  11.         ret = placeValue:format(num / 1000000) .. " Mil" -- million
  12.     elseif num >= 1000 then
  13.         ret = placeValue:format(num / 1000) .. "k" -- thousand
  14.     else
  15.         ret = num -- hundreds
  16.     end
  17.     return ret
  18. end
then re-enable the commented out self.text at the bottom of my code
__________________
  Reply With Quote
09-25-17, 10:51 AM   #2
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
ok so i figured out how to make it work, but when going into the billions i want to force 3 numbers deep,

so instead of it saying 4 billion only, i want it to say,.... 4.25 or 6.99 or so on, here is my code the fix is at the bottom

starting at
local bugfix and continuing to the end

Lua Code:
  1. --Thank you for your help
  2. --SDPhantom
  3. --Phanx
  4. --Fizzlemizz
  5. local AXP_COLOR = { r = 0.6, g = 0.2, b = 0.1 }
  6. --Lets set up the Frame
  7. local derArtifactBar = CreateFrame("Statusbar", "derArtifactBar",artifactFrame)
  8.     derArtifactBar:SetPoint("CENTER", 0, 0)
  9.     derArtifactBar:SetHeight(18)
  10.     derArtifactBar:SetWidth(artifactFrame:GetWidth() * .968)
  11.     derArtifactBar:SetStatusBarTexture("Interface\\AddOns\\_Deranjata\\media\\cast\\Waterline")
  12.     derArtifactBar:SetStatusBarColor(AXP_COLOR.r, AXP_COLOR.g, AXP_COLOR.b, 0.5)
  13.     derArtifactBar:SetBackdrop({
  14.     bgFile =  "Interface\\AddOns\\_Deranjata\\media\\cast\\Lines",
  15.     insets = { left = 1, right = 1, top = 1, bottom = 1 }
  16.     })
  17. derArtifactBar:SetBackdropColor(0.1, 0.1, 0.1)
  18. derArtifactBar:SetBackdropBorderColor(0.6, 0.6, 0.6)
  19. --lets clear any text then set out centerpoint
  20. derArtifactBar.Text=derArtifactBar:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  21. derArtifactBar.Text:SetPoint("CENTER")      
  22.  
  23. --Registering out watched events
  24. derArtifactBar:RegisterEvent("PLAYER_ENTERING_WORLD")
  25. derArtifactBar:RegisterEvent("ARTIFACT_XP_UPDATE")
  26. derArtifactBar:RegisterEvent("UNIT_INVENTORY_CHANGED")
  27.  
  28. -- now lets update the position and text on the bar so we can always have accurate info
  29. derArtifactBar:SetScript("OnEvent", function(self, event, ...)
  30.     if not HasArtifactEquipped() then self:Hide() return end
  31.     self:Show()
  32.     local itemID, altItemID, name, icon, xp, pointsSpent, quality, artifactAppearanceID, appearanceModID, itemAppearanceID, altItemAppearanceID, altOnTop, artifactTier = C_ArtifactUI.GetEquippedArtifactInfo()
  33.     local numPoints, artifactXP, xpForNextPoint = MainMenuBar_GetNumArtifactTraitsPurchasableFromXP(pointsSpent, xp, artifactTier)
  34.     self:SetMinMaxValues(0,xpForNextPoint)
  35.     self:SetValue(artifactXP)
  36.  
  37.     --self.Text:SetFormattedText("Artifact XP: %d / %d       +%d Points",artifactXP,xpForNextPoint,numPoints)
  38. --if artifactXP >= 1000000000  then
  39.  --  local bugFix = artifactXP/1000000--xpForNextPoint
  40.   -- else
  41.   -- local bugFix = 9494949--artifactXP/1000000
  42.  
  43.    
  44. -- end  
  45. local bugFix
  46. local append
  47.  local placeValue = ("%%.%df"):format(places or 0)
  48.     if not (artifactXP) then
  49.         return 0
  50.     elseif (artifactXP) >= 1000000000000 then
  51.         bugFix = placeValue:format(artifactXP / 1000000000000)-- .. --" Tril" -- trillion
  52.         append =" Tril"
  53.     elseif artifactXP >= 1000000000 then
  54.         bugFix = placeValue:format(artifactXP / 1000000000)-- ..-- " Bil" -- billion
  55.         append =" Bil"
  56.     elseif artifactXP >= 1000000 then
  57.         bugFix = placeValue:format(artifactXP / 1000000) --.. --" Mil" -- million
  58.         append =" Mil"
  59.     else
  60.         bugFix = artifactXP -- hundreds
  61.     end
  62.  
  63. local nextPoint
  64. local appendNext
  65.  local placeValue = ("%%.%df"):format(places or 0)
  66.     if not (xpForNextPoint) then
  67.         return 0
  68.     elseif (xpForNextPoint) >= 1000000000000 then
  69.         nextPoint = placeValue:format(xpForNextPoint / 1000000000000)-- .. --" Tril" -- trillion
  70.         appendNext =" Tril"
  71.     elseif xpForNextPoint >= 1000000000 then
  72.         nextPoint = placeValue:format(xpForNextPoint / 1000000000)-- ..-- " Bil" -- billion
  73.         appendNext =" Bil"
  74.     elseif xpForNextPoint >= 1000000 then
  75.         nextPoint = placeValue:format(xpForNextPoint / 1000000) --.. --" Mil" -- million
  76.         appendNext =" Mil"
  77.     else
  78.         nextPoint = xpForNextPoint -- hundreds
  79.     end
  80.    
  81.    self.Text:SetFormattedText("Current %d%s/%d%s    +%d Points",bugFix,append,nextPoint,appendNext,numPoints)
  82. end)
__________________
  Reply With Quote
09-25-17, 12:42 PM   #3
Kakjens
A Cliff Giant
Join Date: Apr 2017
Posts: 75
Why you are not using calls to the function in the first post? The readability of the code should improve.
For billions and trillions you might want to use "%.2f". If need more assistance, post.
  Reply With Quote
09-25-17, 12:48 PM   #4
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
Originally Posted by Kakjens View Post
Why you are not using calls to the function in the first post? The readability of the code should improve.
For billions and trillions you might want to use "%.2f". If need more assistance, post.
how would i write that in, ive tried replacing my %%.%df with it already and i get errors well not errors but it shifts my 4 billion to 0
__________________
  Reply With Quote
09-25-17, 02:20 PM   #5
Kakjens
A Cliff Giant
Join Date: Apr 2017
Posts: 75
Extra local variable
Lua Code:
  1. local placeValue1 = ("%%.%df"):format(places or 2)
and for billions and trillions instead of placeValue use placeValue1.
  Reply With Quote
09-25-17, 03:45 PM   #6
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
ok so i had tried what you suggested, and came up with bad juju, it litteraly cut my current to next level in half and thats all

so here we go again i made some changes, just to get out of the bug fix coding as i was doing adn renamed things to what i though would be ok

im going to post the entire script here so all events are shown

what is happening.
before the fix, stack overflow issue

after the fix
no more stack overflow Errors
However

my druid shows 4 Mil / 39Mil which is correct
Pally shows 900 Mil / 4 Bil which is correct
Warrior shows 100 / 300 which is correct
and so on

my Desired Result if artifact xp to next and artifact currently in my stash

is more then 1,000,000
please for the love of god add a period and 2 digits behind.
i.e. 1.05 mil , 1.15 bil, 4.05 bil, 900 mil, 45 bil and so on

here is all of my code
someone please rip me appart and tell me what stupid crap ive done cause im goin batty

Lua Code:
  1. --Thank you for your help
  2. --SDPhantom
  3. --Phanx
  4. --Fizzlemizz
  5. local AXP_COLOR = { r = 0.6, g = 0.2, b = 0.1 }
  6. --Lets set up the Frame
  7. local derArtifactBar = CreateFrame("Statusbar", "derArtifactBar",artifactFrame)
  8.     derArtifactBar:SetPoint("CENTER", 0, 0)
  9.     derArtifactBar:SetHeight(18)
  10.     derArtifactBar:SetWidth(artifactFrame:GetWidth() * .968)
  11.     derArtifactBar:SetStatusBarTexture("Interface\\AddOns\\_Deranjata\\media\\cast\\Waterline")
  12.     derArtifactBar:SetStatusBarColor(AXP_COLOR.r, AXP_COLOR.g, AXP_COLOR.b, 0.5)
  13.     derArtifactBar:SetBackdrop({
  14.     bgFile =  "Interface\\AddOns\\_Deranjata\\media\\cast\\Lines",
  15.     insets = { left = 1, right = 1, top = 1, bottom = 1 }
  16.     })
  17. derArtifactBar:SetBackdropColor(0.1, 0.1, 0.1)
  18. derArtifactBar:SetBackdropBorderColor(0.6, 0.6, 0.6)
  19. --lets clear any text then set out centerpoint
  20. derArtifactBar.Text=derArtifactBar:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  21. derArtifactBar.Text:SetPoint("CENTER")      
  22.  
  23. --Registering out watched events
  24. derArtifactBar:RegisterEvent("PLAYER_ENTERING_WORLD")
  25. derArtifactBar:RegisterEvent("ARTIFACT_XP_UPDATE")
  26. derArtifactBar:RegisterEvent("UNIT_INVENTORY_CHANGED")
  27.  
  28. -- now lets update the position and text on the bar so we can always have accurate info
  29. derArtifactBar:SetScript("OnEvent", function(self, event, ...)
  30.     if not HasArtifactEquipped() then self:Hide() return end
  31.     self:Show()
  32.     local itemID, altItemID, name, icon, xp, pointsSpent, quality, artifactAppearanceID, appearanceModID, itemAppearanceID, altItemAppearanceID, altOnTop, artifactTier = C_ArtifactUI.GetEquippedArtifactInfo()
  33.     local numPoints, artifactXP, xpForNextPoint = MainMenuBar_GetNumArtifactTraitsPurchasableFromXP(pointsSpent, xp, artifactTier)
  34.     self:SetMinMaxValues(0,xpForNextPoint)
  35.     self:SetValue(artifactXP)
  36.  
  37. --Begin Stack Overflow Fix
  38.  
  39. local setCurrentAXP
  40. local appendCurrentAXP
  41.  local placeValue1 =("%%.%df"):format(places or 0)
  42.     if not (artifactXP) then
  43.         return 0
  44.     elseif (artifactXP) >= 1000000000000 then
  45.         setCurrentAXP = placeValue1:format(artifactXP / 1000000000000)
  46.         appendCurrentAXP =" Tril"
  47.     elseif artifactXP >= 1000000000 then
  48.         setCurrentAXP = placeValue1:format(artifactXP / 1000000000)
  49.         appendCurrentAXP =" Bil"
  50.     elseif artifactXP >= 1000000 then
  51.         setCurrentAXP = placeValue1:format(artifactXP / 1000000)
  52.         appendCurrentAXP =" Mil"
  53.     else
  54.         setCurrentAXP = artifactXP -- hundreds
  55.         appendCurrentAXP =" "
  56.     end
  57.  
  58. local setNextPoint
  59. local setAppendNext
  60.  local placeValue = ("%%.%df"):format(places or 0)
  61.     if not (xpForNextPoint) then
  62.         return 0
  63.     elseif (xpForNextPoint) >= 1000000000000 then
  64.         setNextPoint = placeValue:format(xpForNextPoint / 1000000000000)
  65.         setAppendNext =" Tril"
  66.     elseif xpForNextPoint >= 1000000000 then
  67.         setNextPoint = placeValue:format(xpForNextPoint / 1000000000)
  68.         setAppendNext =" Bil"
  69.     elseif xpForNextPoint >= 1000000 then
  70.         setNextPoint = placeValue:format(xpForNextPoint / 1000000)
  71.         setAppendNext =" Mil"
  72.     else
  73.         setNextPoint = xpForNextPoint -- hundreds
  74.         setAppendNext =" "
  75.     end
  76.    
  77.     --End Stack Overflow Fix **** also added the variable into the self.text:SetFormattedText Below
  78.    
  79.    self.Text:SetFormattedText("Current %d%s/%d%s    +%d Points",setCurrentAXP,appendCurrentAXP,setNextPoint,setAppendNext,numPoints)
  80. end)
__________________
  Reply With Quote
09-25-17, 04:36 PM   #7
Kakjens
A Cliff Giant
Join Date: Apr 2017
Posts: 75
You had to add variable and use it for billions and trillions instead of replacing it everywhere (and forgetting to change "or 0" into "or 2"). Nevertheless, below is untested code:
Lua Code:
  1. --Thank you for your help
  2. --SDPhantom
  3. --Phanx
  4. --Fizzlemizz
  5. local AXP_COLOR = { r = 0.6, g = 0.2, b = 0.1 }
  6. --Lets set up the Frame
  7. local derArtifactBar = CreateFrame("Statusbar", "derArtifactBar",artifactFrame)
  8.     derArtifactBar:SetPoint("CENTER", 0, 0)
  9.     derArtifactBar:SetHeight(18)
  10.     derArtifactBar:SetWidth(artifactFrame:GetWidth() * .968)
  11.     derArtifactBar:SetStatusBarTexture("Interface\\AddOns\\_Deranjata\\media\\cast\\Waterline")
  12.     derArtifactBar:SetStatusBarColor(AXP_COLOR.r, AXP_COLOR.g, AXP_COLOR.b, 0.5)
  13.     derArtifactBar:SetBackdrop({
  14.     bgFile =  "Interface\\AddOns\\_Deranjata\\media\\cast\\Lines",
  15.     insets = { left = 1, right = 1, top = 1, bottom = 1 }
  16.     })
  17. derArtifactBar:SetBackdropColor(0.1, 0.1, 0.1)
  18. derArtifactBar:SetBackdropBorderColor(0.6, 0.6, 0.6)
  19. --lets clear any text then set out centerpoint
  20. derArtifactBar.Text=derArtifactBar:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  21. derArtifactBar.Text:SetPoint("CENTER")      
  22.  
  23. --Registering out watched events
  24. derArtifactBar:RegisterEvent("PLAYER_ENTERING_WORLD")
  25. derArtifactBar:RegisterEvent("ARTIFACT_XP_UPDATE")
  26. derArtifactBar:RegisterEvent("UNIT_INVENTORY_CHANGED")
  27.  
  28. --function for beautiful numbers
  29. local function ReadableNumber(num)
  30.     local ret
  31.     local placeValue = ("%%.%df"):format(0) --probably can be improved into "%.0f"
  32.     local placeValue1 = ("%%.%df"):format(2) --probably can be improved "%.2f"
  33.     if not num then
  34.         return "0 "
  35.     elseif num >= 1000000000000 then
  36.         ret = placeValue1:format(num / 1000000000000) .. " Tril" -- trillion
  37.     elseif num >= 1000000000 then
  38.         ret = placeValue1:format(num / 1000000000)  .. " Bil" -- billion
  39.     elseif num >= 1000000 then
  40.         ret = placeValue:format(num / 1000000) .. " Mil"-- million
  41.     elseif num >= 1000 then
  42.         ret = placeValue:format(num / 1000) .. "k" -- thousand
  43.     else
  44.         ret = num .. " "-- hundreds
  45.     end
  46.     return ret
  47. end
  48.  
  49. -- now lets update the position and text on the bar so we can always have accurate info
  50. derArtifactBar:SetScript("OnEvent", function(self, event, ...)
  51.     if not HasArtifactEquipped() then self:Hide() return end
  52.     self:Show()
  53.     local itemID, altItemID, name, icon, xp, pointsSpent, quality, artifactAppearanceID, appearanceModID, itemAppearanceID, altItemAppearanceID, altOnTop, artifactTier = C_ArtifactUI.GetEquippedArtifactInfo()
  54.     local numPoints, artifactXP, xpForNextPoint = MainMenuBar_GetNumArtifactTraitsPurchasableFromXP(pointsSpent, xp, artifactTier)
  55.     self:SetMinMaxValues(0,xpForNextPoint)
  56.     self:SetValue(artifactXP)
  57.  
  58. --Begin Stack Overflow Fix
  59.  
  60. local currentAXP = ReadableNumber(artifactXP)
  61. local nextAXP = ReadableNumber(xpForNextPoint)
  62.  
  63.     --End Stack Overflow Fix **** also added the variable into the self.text:SetFormattedText Below
  64.    
  65.    self.Text:SetFormattedText("Current %s/%s    +%d Points",currentAXP, nextAXP, numPoints)
  66. end)
Several things could be improved, for example, reducing of used variables.

Last edited by Kakjens : 09-25-17 at 06:13 PM.
  Reply With Quote
09-25-17, 04:56 PM   #8
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
sorry to say this one gives me the same problem i was having, still not the number formatting im looking for /Sadpanda
__________________
  Reply With Quote
09-25-17, 05:18 PM   #9
Kakjens
A Cliff Giant
Join Date: Apr 2017
Posts: 75
Still don't work after the last edit?
  Reply With Quote
09-25-17, 05:21 PM   #10
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
Originally Posted by Kakjens View Post
Still don't work after the last edit?
no sir, just the same output as my own code, just prettier
__________________
  Reply With Quote
09-25-17, 06:19 PM   #11
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Maybe I'm misunderstanding but:
Lua Code:
  1. local function ReadableNumber(num)
  2.         local ret
  3.         local placeValue = ("%%.%df"):format(2) --probably can be improved into "%.0f"
  4.         if not num then
  5.             return "0 "
  6.         elseif num >= 1000000000000 then
  7.             ret = placeValue:format(num / 1000000000000) .. " Tril" -- trillion
  8.         elseif num >= 1000000000 then
  9.             ret = placeValue:format(num / 1000000000)  .. " Bil" -- billion
  10.         elseif num >= 1000000 then
  11.             ret = placeValue:format(num / 1000000) .. " Mil"-- million
  12.         elseif num >= 1000 then
  13.             ret = placeValue:format(num / 1000) .. "k" -- thousand
  14.         else
  15.             ret = num .. " "-- hundreds
  16.         end
  17.         return ret
  18.     end
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
09-25-17, 06:20 PM   #12
Kakjens
A Cliff Giant
Join Date: Apr 2017
Posts: 75
Typos, typos everywhere. Hopefully the last missed place. Try the last code by me.
FizzleMizz: in the second post first line I see specification for special treatment of billions(3 digits). I extended it to trillions.
Edit. Or was it meant beginning with million?

Last edited by Kakjens : 09-25-17 at 06:34 PM.
  Reply With Quote
09-25-17, 06:34 PM   #13
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Originally Posted by Uitat View Post
is more then 1,000,000
please for the love of god add a period and 2 digits behind.
i.e. 1.05 mil , 1.15 bil, 4.05 bil, 900 mil, 45 bil and so on
I'm not sure if the means everything over a mil. has 2 places (which is what I took it as.)

If the desire is that anything with exact multiples of a mil., bil, tril. will show no places then you would need to add a mod() operation to see if there is any remainder and format accordingly.

The general idea (could be cleaner):
Code:
    local function ReadableNumber(num)
        local ret
        local placeValue = ("%%.%df"):format(2) --probably can be improved into "%.0f"
        if not num then
            return "0 "
        elseif num >= 1000000000000 then
            if mod(num, 1000000000000) == 0 then
            	ret = num / 1000000000000 .. " Tril"
            else
            	ret = placeValue:format(num / 1000000000000) .. " Tril" -- trillion
            end
        elseif num >= 1000000000 then
            if mod(num, 1000000000) == 0 then
            	ret = num / 1000000000 .. " Bil"
            else
            	ret = placeValue:format(num / 1000000000)  .. " Bil" -- billion
            end
        elseif num >= 1000000 then
            if mod(num, 1000000) == 0 then
            	ret = num / 1000000 .. " Mil"
            else
            	ret = placeValue:format(num / 1000000) .. " Mil"-- million
            end
        elseif num >= 1000 then
            ret = placeValue:format(num / 1000) .. "k" -- thousand
        else
            ret = num .. " "-- hundreds
        end
        return ret
    end
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 09-25-17 at 06:44 PM.
  Reply With Quote
09-25-17, 07:03 PM   #14
Kakjens
A Cliff Giant
Join Date: Apr 2017
Posts: 75
Desired result isn't well-written. Also might be missing specification that 1.6 millions would be displayed as 1.6 instead of 1.60.
I feel that your code would display 1000010 as 1.00 Mil.
I think that by creative use of tonumber(format) the same would be more efficiently achieved.
  Reply With Quote
09-25-17, 07:16 PM   #15
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
There's also the problem (Edit: as mentioned by Kakjens) with small remainders giving a result of x.00 Mil. so it could be extended too:
Lua Code:
  1. --function for beautiful numbers
  2. local floor = math.floor
  3. local strlen, strsub = string.len, string.sub
  4. local function ReadableNumber(num)
  5.     local ret
  6.     local placeValue = ("%%.%df"):format(2) --probably can be improved into "%.0f"
  7.     local prefix = ""
  8.     if not num then
  9.         return "0 "
  10.     elseif num >= 1000000000000 then
  11.         prefix = " Tril" -- trillion
  12.         if mod(num, 1000000000000) < 10000000000 then
  13.             ret = floor(num / 1000000000000)
  14.         else
  15.             ret = placeValue:format(num / 1000000000000)
  16.         end
  17.     elseif num >= 1000000000 then
  18.         prefix = " Bil" -- billion
  19.         if mod(num, 1000000000) < 10000000 then
  20.             ret = floor(num / 1000000000)
  21.         else
  22.             ret = placeValue:format(num / 1000000000)
  23.         end
  24.     elseif num >= 1000000 then
  25.         prefix = " Mil" -- million
  26.         if mod(num, 1000000) < 10000 then
  27.             ret = floor(num / 1000000)
  28.         else
  29.             ret = placeValue:format(num / 1000000)
  30.         end
  31.     elseif num >= 1000 then
  32.         prefix = "k" -- thousand
  33.         ret = placeValue:format(num / 1000)
  34.     else
  35.         ret = num
  36.     end
  37.     local len = strlen(ret)
  38.     if len > 3 then
  39.         if strsub(ret, len-2, len-2) == "." and strsub(ret, len) == "0" then
  40.             ret = strsub(ret, 1, len-1)
  41.         end
  42.     end
  43.     return ret..prefix
  44. end
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 09-25-17 at 09:54 PM.
  Reply With Quote
09-25-17, 10:09 PM   #16
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
[quote=Fizzlemizz;325288]There's also the problem (Edit: as mentioned by Kakjens) with small remainders giving a result of x.00 Mil. so it could be extended too:

ok the question is how do i implement this with my self.text at the bottom

Lua Code:
  1. --Thank you for your help
  2. --SDPhantom
  3. --Phanx
  4. --Fizzlemizz
  5. local AXP_COLOR = { r = 0.6, g = 0.2, b = 0.1 }
  6. --Lets set up the Frame
  7. local derArtifactBar = CreateFrame("Statusbar", "derArtifactBar",artifactFrame)
  8.     derArtifactBar:SetPoint("CENTER", 0, 0)
  9.     derArtifactBar:SetHeight(18)
  10.     derArtifactBar:SetWidth(artifactFrame:GetWidth() * .968)
  11.     derArtifactBar:SetStatusBarTexture("Interface\\AddOns\\_Deranjata\\media\\cast\\Waterline")
  12.     derArtifactBar:SetStatusBarColor(AXP_COLOR.r, AXP_COLOR.g, AXP_COLOR.b, 0.5)
  13.     derArtifactBar:SetBackdrop({
  14.     bgFile =  "Interface\\AddOns\\_Deranjata\\media\\cast\\Lines",
  15.     insets = { left = 1, right = 1, top = 1, bottom = 1 }
  16.     })
  17. derArtifactBar:SetBackdropColor(0.1, 0.1, 0.1)
  18. derArtifactBar:SetBackdropBorderColor(0.6, 0.6, 0.6)
  19. --lets clear any text then set out centerpoint
  20. derArtifactBar.Text=derArtifactBar:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  21. derArtifactBar.Text:SetPoint("CENTER")      
  22.  
  23. --Registering out watched events
  24. derArtifactBar:RegisterEvent("PLAYER_ENTERING_WORLD")
  25. derArtifactBar:RegisterEvent("ARTIFACT_XP_UPDATE")
  26. derArtifactBar:RegisterEvent("UNIT_INVENTORY_CHANGED")
  27.  
  28. -- now lets update the position and text on the bar so we can always have accurate info
  29. derArtifactBar:SetScript("OnEvent", function(self, event, ...)
  30.     if not HasArtifactEquipped() then self:Hide() return end
  31.     self:Show()
  32.     local itemID, altItemID, name, icon, xp, pointsSpent, quality, artifactAppearanceID, appearanceModID, itemAppearanceID, altItemAppearanceID, altOnTop, artifactTier = C_ArtifactUI.GetEquippedArtifactInfo()
  33.     local numPoints, artifactXP, xpForNextPoint = MainMenuBar_GetNumArtifactTraitsPurchasableFromXP(pointsSpent, xp, artifactTier)
  34.     self:SetMinMaxValues(0,xpForNextPoint)
  35.     self:SetValue(artifactXP)
  36.  
  37. --Begin Stack Overflow Fix
  38. --function for beautiful numbers
  39. local floor = math.floor
  40. local strlen, strsub = string.len, string.sub
  41. local function ReadableNumber(num)
  42.     local ret
  43.     local placeValue = ("%%.%df"):format(2) --probably can be improved into "%.0f"
  44.     local prefix = ""
  45.     if not num then
  46.         return "0 "
  47.     elseif num >= 1000000000000 then
  48.         prefix = " Tril" -- trillion
  49.         if mod(num, 1000000000000) < 10000000000 then
  50.             ret = floor(num / 1000000000000)
  51.         else
  52.             ret = placeValue:format(num / 1000000000000) .. " Tril" -- trillion
  53.         end
  54.     elseif num >= 1000000000 then
  55.         prefix = " Bil" -- billion
  56.         if mod(num, 1000000000) < 10000000 then
  57.             ret = floor(num / 1000000000)
  58.         else
  59.             ret = placeValue:format(num / 1000000000)
  60.         end
  61.     elseif num >= 1000000 then
  62.         prefix = " Mil" -- million
  63.         if mod(num, 1000000) < 10000 then
  64.             ret = floor(num / 1000000)
  65.         else
  66.             ret = placeValue:format(num / 1000000)
  67.         end
  68.     elseif num >= 1000 then
  69.         prefix = "k" -- thousand
  70.         ret = placeValue:format(num / 1000)
  71.     else
  72.         ret = num
  73.     end
  74.     local len = strlen(ret)
  75.     if len > 3 then
  76.         if strsub(ret, len-2, len-2) == "." and strsub(ret, len) == "0" then
  77.             ret = strsub(ret, 1, len-1)
  78.         end
  79.     end
  80.     return ret..prefix
  81. end
  82.  
  83. self.Text:SetFormattedText("Current %d%s/%d%s    +%d Points",artifactXP,prefix,xpForNextPoint,prefix,numPoints)
  84. end)
__________________

Last edited by Uitat : 09-25-17 at 10:18 PM.
  Reply With Quote
09-25-17, 10:22 PM   #17
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Most of the code is from Kakjens, I just messed with it a bit.

Edited to reduce the # coded IF statements.

Lua Code:
  1. --Thank you for your help
  2. --SDPhantom
  3. --Phanx
  4. --Fizzlemizz
  5. --function for beautiful numbers
  6. local floor = math.floor
  7. local strlen, strsub = string.len, string.sub
  8. local function FormatNumber(num, multi, rem)
  9.     if mod(num, multi) < rem then
  10.         return floor(num / multi)
  11.     else
  12.         local placeValue = ("%%.%df"):format(2)
  13.         return placeValue:format(num / multi)
  14.     end
  15. end
  16. local function ReadableNumber(num)
  17.     local ret
  18.     local prefix = ""
  19.     if not num then
  20.         return "0 "
  21.     elseif num >= 1000000000000 then
  22.         prefix = " Tril" -- trillion
  23.         ret = FormatNumber(num, 1000000000000, 10000000000)
  24.     elseif num >= 1000000000 then
  25.         prefix = " Bil" -- billion
  26.         ret = FormatNumber(num, 1000000000, 10000000)
  27.     elseif num >= 1000000 then
  28.         prefix = " Mil" -- million
  29.         ret = FormatNumber(num, 1000000, 10000)
  30.     elseif num >= 1000 then
  31.         prefix = "k" -- thousand
  32.         local placeValue = ("%%.%df"):format(2)
  33.         ret = placeValue:format(num / 1000)
  34.     else
  35.         ret = num
  36.     end
  37.     local len = strlen(ret)
  38.     if len > 3 then
  39.         if strsub(ret, len-2, len-2) == "." and strsub(ret, len) == "0" then
  40.             ret = strsub(ret, 1, len-1)
  41.         end
  42.     end
  43.     return ret..prefix
  44. end
  45.  
  46. local AXP_COLOR = { r = 0.6, g = 0.2, b = 0.1 }
  47. --Lets set up the Frame
  48. local derArtifactBar = CreateFrame("Statusbar", "derArtifactBar",artifactFrame)
  49. derArtifactBar:SetPoint("CENTER", 0, 0)
  50. derArtifactBar:SetHeight(18)
  51. derArtifactBar:SetWidth(artifactFrame:GetWidth() * .968)
  52. derArtifactBar:SetStatusBarTexture("Interface\\AddOns\\_Deranjata\\media\\cast\\Waterline")
  53. derArtifactBar:SetStatusBarColor(AXP_COLOR.r, AXP_COLOR.g, AXP_COLOR.b, 0.5)
  54. derArtifactBar:SetBackdrop({
  55.         bgFile =  "Interface\\AddOns\\_Deranjata\\media\\cast\\Lines",
  56.         insets = { left = 1, right = 1, top = 1, bottom = 1 }
  57.     })
  58. derArtifactBar:SetBackdropColor(0.1, 0.1, 0.1)
  59. derArtifactBar:SetBackdropBorderColor(0.6, 0.6, 0.6)
  60. --lets clear any text then set out centerpoint
  61. derArtifactBar.Text=derArtifactBar:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  62. derArtifactBar.Text:SetPoint("CENTER")      
  63.  
  64. --Registering out watched events
  65. derArtifactBar:RegisterEvent("PLAYER_ENTERING_WORLD")
  66. derArtifactBar:RegisterEvent("ARTIFACT_XP_UPDATE")
  67. derArtifactBar:RegisterEvent("UNIT_INVENTORY_CHANGED")
  68.  
  69. -- now lets update the position and text on the bar so we can always have accurate info
  70. derArtifactBar:SetScript("OnEvent", function(self, event, ...)
  71.     if not HasArtifactEquipped() then self:Hide() return end
  72.     self:Show()
  73.     local itemID, altItemID, name, icon, xp, pointsSpent, quality, artifactAppearanceID, appearanceModID, itemAppearanceID, altItemAppearanceID, altOnTop, artifactTier = C_ArtifactUI.GetEquippedArtifactInfo()
  74.     local numPoints, artifactXP, xpForNextPoint = MainMenuBar_GetNumArtifactTraitsPurchasableFromXP(pointsSpent, xp, artifactTier)
  75.     self:SetMinMaxValues(0,xpForNextPoint)
  76.     self:SetValue(artifactXP)
  77.  
  78.     artifactXP = ReadableNumber(artifactXP)
  79.     xpForNextPoint = ReadableNumber(xpForNextPoint)
  80.  
  81.     self.Text:SetFormattedText("Current %s/%s    +%d Points",artifactXP, xpForNextPoint, numPoints)
  82. end)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 09-25-17 at 11:40 PM.
  Reply With Quote
09-26-17, 09:59 AM   #18
Uitat
A Chromatic Dragonspawn
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 162
best i can tell yes this did what i intended, always giving me a minimum of 3 visible characters, weather its 1.25 12.5 or 125,

sometimes fizzle i swear your a genius
__________________
  Reply With Quote
09-26-17, 11:28 AM   #19
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Originally Posted by Uitat View Post
best i can tell yes this did what i intended, always giving me a minimum of 3 visible characters, weather its 1.25 12.5 or 125,

sometimes fizzle i swear your a genius
Credit should go to Kakjens.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
09-26-17, 12:24 PM   #20
Kakjens
A Cliff Giant
Join Date: Apr 2017
Posts: 75
The most of the code was provided by Uitat, so Fizzlemizz should get credit, if only because of understanding (and implementing) what Uitat meant. I only slightly improved the usage of ReadableNumber.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » code integration

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