[Home] [Downloads] [Search] [Help/forum]

Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Miniwindows
. . -> [Subject]  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] Refresh page

Posted by Xinefus   (106 posts)  [Biography] bio
Date Tue 10 Nov 2020 09:30 PM (UTC)
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.

[Go to top] top

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

Posted by Xinefus   (106 posts)  [Biography] bio
Date Reply #2 on Wed 11 Nov 2020 01:20 AM (UTC)
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 )
      return tostring(val)

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

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

[Go to top] top

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

if val >= 10^18 then


if val >= 10E18 then

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Xinefus   (106 posts)  [Biography] bio
Date Reply #5 on Wed 11 Nov 2020 06:06 PM (UTC)
Thank you!

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

Have a great week.
[Go to top] 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.


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

Go to topic:           Search the forum

[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]