Stuf LUA help
I'm looking for a custom lua code to show curhp/maxhp followed by perchp with two decimals for Stuf Unit Frames. The current code I'm using which only shows perchp with two decimals -
Code:
function(unit, cache, textframe) 300000/500000 | 60.00% 60.00% | 300000/500000 Thanks for any help! |
Quote:
Because we need to know what previous function do with our return. Or you can show us whole .lua or .xml file, it will be more easy. Solution will looks something like this: Lua Code:
|
Quote:
Lua Code:
Or cleaner: Lua Code:
|
Quote:
60.00% | 300000/500000 but the text would disappear each time. How would I go about switching it around? Edit: Lua Code:
Figured it out after messing around a bit! However, I've now noticed that the numbers are not being shortened (I have my STUF options to shorten starting at 1 million). Instead of showing 1M, its showing 1000000. Any way to fix this? Ideally I'd like it to show like this - 60.00% | 3.0M / 5.0M 5.00% | 250000 / 5.0M |
The simplest way would be to just call the Blizzard function for short number display:
Code:
-- After this line: |
Long ago I had figured out a solution but I've now lost it and I'm looking for it again --
The above solution only shortens it as so - 60.00% | 3000K / 5000K I would prefer it to start shortening at 1000000 as so - 60.00% | 3.0M / 5.0M 5.00% | 250000 / 5.0M Thanks for any help! Edit: Lua Code:
Current code I'm using. |
This is something I do to format numbers and group into thousands/millions.
lua Code:
Of course, you'll have to tweak the amounts at lines 4 and 6 to get it to shorten 5,000,000 as 5M rather than 5,000K, but you get the point. |
Could you explain what happens in lines 9-14 because for something that should have a simple display the code seems too complex.
|
Couldn't tell you honestly. When I needed a function like that I googled it and this is what I got as a result.
It works so I didn't bother messing with it any further, but if you find that this part of the code isn't actually needed it can be removed, of course. |
Quote:
|
gsub returns 1, the new string and 2, the number of matches. When the number of matches == 0 (in this case k) break out of the loop.
|
Quote:
Fizzlemizz, thanks for explanation but I meant to ask what the code accomplishes instead of what it does. But won't this become unneeded after 7.3.5 with ilvl (and stat) squishes? |
Holy crap, I just realized. "Of you're." What kind of typo is that?
Anyway patterns are too much for my brain to comprehend tbh, but the end result is that it takes the number and adds comma separator (so 10000 becomes 10,000.) If you feel like you can understand it you can probably read up on documentation to figure out exactly what the pattern matches. Maybe it won't be as useful anymore once they do the next numbers squish, but that's hardly a reason not to make addons for the current game. ;p |
Ammako, human language is relatively fault-tolerant (unlike programming ones), so was able to guess what you intended to write.
Thanks for explaining the result of this loop with gsub and link. No experience with pattern matching but I believe it does something like: "If, starting from beginning, there's at least one digit (1-st group) followed by three digits (2-nd group), then between 1-st and second group insert comma". Sounds somehow similar to BreakupLageNumbers. Seeing that the applicable numbers for this procedure are between 999 and 100000, I wonder if it would be more efficient to use extra "if" instead of "while" loop. Edit. About writing the code which won't be used after this patch: I would be really hesitant to do it. I would think about whether having the exact desired output would be worth the trouble or be content with, for example, AbbreviateLargeNumbers. |
Quote:
Using the while statement is more of a maintenance thing so you don't have to keep adding "if" statements as the numbers get larger while requiring less iterations when the numbers a smaller. |
Ok so I took the time to understand the pattern, I might as well explain how it works.
So when you feed it a number, it'll start looking from the beginning of the string for something that may or may not begin with a - character and has at least four leading digits, stopping whenever it hits anything else (in this case, a comma character.) After it matches, it adds a comma between the two parts. ^(-?%d+)(%d%d%d) : 10000000 --> (10000),(000) --> (10),(000),000 --> 10,000,000 (no more matches.) |
All times are GMT -6. The time now is 02:05 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI