09-25-17, 06:54 AM | #1 |
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:
want to add this in to replace line local bugFix = artifactXP/xpForNextPoint self.Text:SetFormattedText("Current %d +%d Points",bugFix,numPoints) Lua Code:
__________________
|
|
09-25-17, 10:51 AM | #2 |
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:
__________________
|
|
09-25-17, 12:42 PM | #3 |
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. |
|
09-25-17, 12:48 PM | #4 |
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
__________________
|
|
09-25-17, 02:20 PM | #5 |
Extra local variable
Lua Code:
|
|
09-25-17, 03:45 PM | #6 |
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:
__________________
|
|
09-25-17, 04:36 PM | #7 |
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:
Last edited by Kakjens : 09-25-17 at 06:13 PM. |
|
09-25-17, 04:56 PM | #8 |
sorry to say this one gives me the same problem i was having, still not the number formatting im looking for /Sadpanda
__________________
|
|
09-25-17, 05:18 PM | #9 |
Still don't work after the last edit?
|
|
09-25-17, 05:21 PM | #10 |
no sir, just the same output as my own code, just prettier
__________________
|
|
09-25-17, 06:19 PM | #11 |
Maybe I'm misunderstanding but:
Lua Code:
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. |
|
09-25-17, 06:20 PM | #12 |
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. |
|
09-25-17, 06:34 PM | #13 | |
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. |
||
09-25-17, 07:03 PM | #14 |
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. |
|
09-25-17, 07:16 PM | #15 |
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:
__________________
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. |
|
09-25-17, 10:09 PM | #16 |
[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:
__________________
Last edited by Uitat : 09-25-17 at 10:18 PM. |
|
09-25-17, 10:22 PM | #17 |
Most of the code is from Kakjens, I just messed with it a bit.
Edited to reduce the # coded IF statements. Lua Code:
__________________
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. |
|
09-26-17, 09:59 AM | #18 |
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
__________________
|
|
09-26-17, 11:28 AM | #19 |
Credit should go to Kakjens.
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. |
|
09-26-17, 12:24 PM | #20 |
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.
|
|
WoWInterface » Developer Discussions » Lua/XML Help » code integration |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|