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
➜ Lua
➜ how to offset the bar width with its left size
|
how to offset the bar width with its left size
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Maxhrk
USA (76 posts) Bio
|
| Date
| Thu 16 Jul 2009 05:16 PM (UTC) Amended on Thu 16 Jul 2009 05:17 PM (UTC) by Maxhrk
|
| Message
|
WindowRectOp (win, 2, 0, 0, 0, 0, ColourNameToRGB("sandybrown"))
WindowRectOp (win, 2, 12, 20, 185 * math.floor((tonumber(stat["H"]["current"]) / tonumber(stat["H"]["max"]))), 40, ColourNameToRGB("darkred"))
WindowRectOp (win, 1, 12, 20, 186, 40, ColourNameToRGB("black"))
WindowText(win, "fn", "Health:" .. stat["H"]["current"] .. "/" .. stat["H"]["max"], 14, 24, 0, 0, ColourNameToRGB("black"), false);
this code purpose is to display the bar that show the percent of a certain stat by painting the bar to correct percentage of full size of the bar.
It would be this math formula for above in peusdo code as example:
bar_right_size * (current_hp / max_hp)
When i try to test the bar by set it to 50% as test. however, i saw that does not correctly split bar in neat half. I realized that I should offset the bar's left size. SO how can I do that? thanks! | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Thu 16 Jul 2009 09:58 PM (UTC) |
| Message
| Willfa did a module to do gauges:
http://www.gammon.com.au/forum/bbshowpost.php?id=9097
However your problem is that the WindowRectOp takes a rectangle for the box, not a start and width. So what you need to do is something like:
width = right - left
first_part = width * (current_hp / max_hp)
second_part = width - first_part
Now your first rectangle if from left to left + first_part.
The second one is from left + first_part to left + width.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Maxhrk
USA (76 posts) Bio
|
| Date
| Reply #2 on Fri 17 Jul 2009 12:12 AM (UTC) Amended on Fri 17 Jul 2009 12:33 AM (UTC) by Maxhrk
|
| Message
| I am still confused with how to put them in WindowRectOp. I thought, i should put Second_part at in the 'right' part of WindowRectOp parameter. However it seem that bar passed the bar. I think i must have doing wrong. Can you clear it up for me how it can be done in the code?
Sorry about that.
About the gauge module, I did took poke at it and it seem fairly interesting, but I want to learn it by hand to see how it can be done and learn by it. :) | | Top |
|
| Posted by
| Maxhrk
USA (76 posts) Bio
|
| Date
| Reply #3 on Fri 17 Jul 2009 04:10 AM (UTC) Amended on Fri 17 Jul 2009 04:43 AM (UTC) by Maxhrk
|
| Message
| I think i got it right after reread your comments and it totally made sense now.
here the link of my interesting experiment of my success(!):
http://img102.imageshack.us/img102/6154/mybetaguimush.png
here the link of my result.. athough you can see most of upper part of tan textRectangle is empty.. i am going to put up something else on it soon when I have good idea how to put it on there.
In any case i am extremely happy with the result. :) | | 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.
18,572 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top