Help with string format for miniwindow gauges

Posted by Death on Tue 20 Feb 2018 12:47 AM — 3 posts, 17,017 views.

#0
Hey guys,

I've been spending loads of time figuring out miniwindows, and I've spent some time (not as much as I'd like) trying to learn the code (thanks nick and fiendish for pushing me)

I'm having problems figuring out where to place my string format.

I've currently worked out how to do a number overlay on my gauges, but I've not worked out how to format that number overlay..

I'm looking to put hp/max_hp, and also a percentage.

So far, I've been able to overlay just the current number of hp itself, but I don't quite understand where to place my string.format code.

This is the code where the numbers are overlaid into the gauge.


  WindowText (win, font_id, current,
                             gauge_left + 3, vertical + 1, 0, 0, ColourNameToRGB ("black"))
  WindowText (win, font_id, current,
                             gauge_left + 2, vertical + 1, 0, 0, ColourNameToRGB ("black"))
  WindowText (win, font_id, current,
                             gauge_left + 1, vertical, 0, 0, ColourNameToRGB ("white"))




I've attempted to add
string.format ("%s\t%i / %i (%i%%)"

into my code, but I'm not quite sure where I should place it..
My numbers run off of "current", and "max".

Also, if you could please direct me a tiny bit (link?)
on how the order of the functions work

I.E.
(win, font_id, current,
,
I'm imagining it calls them in order, but I'm not sure how I can add to this to make it all work out. Would I need to add string.format into the code before current to make it call current with the string.format? I've tried this, and it didn't quite work. I just need a tiny bit of help please.

I'm sure I could teach myself the rest, and it would become much easier for me not to bother anyone with asking for help again.

I'd also love to be able to post the code of the updated gauges for public usage, since they'll have been upgraded a bit over the standard Health Gauge by Nick Gammon.


Thank you again.

Vivi
USA Global Moderator #1
You should read http://lua-users.org/wiki/FunctionsTutorial

You should also read the links provided in https://www.mushclient.com/forum/?id=13912&reply=1#reply1

When a function is defined, its definition specifies what inputs it takes and in what order it takes them.
Amended on Tue 20 Feb 2018 02:00 AM by Fiendish
Australia Forum Administrator #2
Template:function=WindowText
WindowText

The documentation for the WindowText script function is available online. It is also in the MUSHclient help file.



From that page:

Quote:

long WindowText(BSTR WindowName, BSTR FontId, BSTR Text, long Left, long Top, long Right, long Bottom, long Colour, BOOL Unicode);


The BSTR part basically means a string. So the 3rd argument is the text of what you are trying to display.





 WindowText (win, font_id, current,
                             gauge_left + 3, vertical + 1, 0, 0, ColourNameToRGB ("black"))


In that case "current" is a string that is being displayed.

Now if you want to replace that by string.format you do exactly that:


 WindowText (win, font_id, string.format ("%i / %i", foo, bar),
                             gauge_left + 3, vertical + 1, 0, 0, ColourNameToRGB ("black"))


Now that will display two numbers (foo and bar) formatted as integers, with a slash between them.