Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Miniwindows ➜ Editing overlay text of miniwindow gauges

Editing overlay text of miniwindow gauges

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Xinefus   (106 posts)  Bio
Date Tue 10 Nov 2020 09:30 PM (UTC)
Message
Hey folks,

I have been working with Fiendish's health_bars_gmcp plugin and modified it for my own mud. I'm coding/working on that rare breed dragonball mud (based on smaug) and they have some pretty large numbers in some of their attributes.

The problem I am trying to get around is that when I show the overlay numbers it many times just runs off into the next or previous gauge unless I make the whole set of gauges wider. Not an ideal solution.

I was wondering if there is a way for me to 'truncate' the numbers from lets say 10000 to 10K or 10.0K? I assume I could use something like string.format but I'm not sure how this would work in the case of this plugin while using DoNextSimpleBar().

Any bit of help in this would be appreciated.

Thanks!
Top

Posted by Xinefus   (106 posts)  Bio
Date Reply #1 on Tue 10 Nov 2020 09:40 PM (UTC)
Message
I just realised I put this in the wrong sub-forum. It probably should be in the miniwindows sub-forum. Sorry guys. :(
Top

Posted by Xinefus   (106 posts)  Bio
Date Reply #2 on Wed 11 Nov 2020 01:20 AM (UTC)
Message
Well, I was a bit premature in asking this question!

I was able to figure it out quite easily once I actually started to read more about DoNextSimpleBar()

I added this
function shorten(val)
    if val >= 10^18 then
      return string.format("%.2fQt", val / 1000000000000000000 )
    elseif val >= 10^15 then
      return string.format("%.2fQu", val / 1000000000000000 )
    elseif val >= 10^12 then
      return string.format("%.2fT", val / 1000000000000 )
    elseif val >= 10^9 then
      return string.format("%.2fB", val / 1000000000 )
    elseif val >= 10^6 then
      return string.format("%.2fM", val / 1000000 )
    elseif val >= 10^3 then
      return string.format("%.2fK", val / 1000 )
    else
      return tostring(val)
    end
end

I then just changed the line in DoNextSimpleBar() to this:
            txt = string.lpad(shorten(num_val), maxlen, ' ').."/"..string.rpad(shorten(num_maxval),maxlen,' ')
Top

Posted by Fiendish   USA  (2,533 posts)  Bio   Global Moderator
Date Reply #3 on Wed 11 Nov 2020 03:07 AM (UTC)
Message
You could also just string.format the number into scientific notation with %e without looking at it.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #4 on Wed 11 Nov 2020 06:58 AM (UTC)
Message
Lua probably pre-calculates constants, but you could change:


if val >= 10^18 then


to


if val >= 10E18 then

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Xinefus   (106 posts)  Bio
Date Reply #5 on Wed 11 Nov 2020 06:06 PM (UTC)
Message
Thank you!

It's working so far the way I intend it.

Have a great week.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


14,774 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.