Register forum user name 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.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Miniwindows ➜ Help with string format for miniwindow gauges

Help with string format for miniwindow gauges

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


Posted by Death   (55 posts)  Bio
Date Tue 20 Feb 2018 12:47 AM (UTC)
Message
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
Top

Posted by Fiendish   USA  (2,558 posts)  Bio   Global Moderator
Date Reply #1 on Tue 20 Feb 2018 01:53 AM (UTC)

Amended on Tue 20 Feb 2018 02:00 AM (UTC) by Fiendish

Message
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.

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

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #2 on Tue 20 Feb 2018 02:27 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


16,161 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.