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 ➜ Tips and tricks ➜ You've got binary in my HTML...

You've got binary in my HTML...

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


Posted by Shadowfyr   USA  (1,790 posts)  Bio
Date Sun 20 Oct 2002 09:35 PM (UTC)

Amended on Sun 20 Oct 2002 10:16 PM (UTC) by Shadowfyr

Message
Mushclient always returns integer values taken direct from the computers memory, thus you run into some problems.. In VBscript some bugs prevent you from using the 'machine' version of colors, so the HTML format it more reliable. This is a major problem:
Machine form:
| (Blue) | (Green) | (Red) |
        \_____  ____/
              \/
        ______/\____
HTML  |/_          _\|
| (Red)  | (Green) | (Blue) |

This means Blue become Red, Yellow become Cyan and the only color that is right when you try to use the returned values is Green.

The solution is to do this:
function GetHTMLColor(color)
  dim High, Mid, Low
  Low = int(color/65536)           ' This was the high byte, so we divide by the lowest
                                   ' value it can contain, this gives up a number between
                                   ' 0-255. Convenient. ;)
  color = color - Low * 65536	  ' Lets subtract what we just recovered from the
                                   ' original so we can get the middle.
  Mid = int(color/256) * 256       ' Here's the middle.
  color = color - Mid              ' Subtract that too.
  High = color * 65536             ' What's left must be our new Hi-Byte, so multiply it
                                   ' to get the correct value.
  GetHTMLColor = High + Mid + Low  ' Add them all up and return the corrected number.
end function


To use the function you would simply do the following:

color = world.normalcolour(5)
fixedcolor = "#" & hex(GetHTMLColor(color))

And presto.. You now have the correct color for using the HTML format. Of course some my ask 'why?', but some commands seemed to dislike using other styles and the '&h' format, which is the machine version, does not work properly under vbscript in all cases.

Note to **Nick**.. Yes this is not that hard to do and there are bound to be people screaming about pointless functions, but it would make life a lot less complicated to have a mushclient function like this:

BSTR FixedColor = world.FixColor(LONG color, BSTR type)

Types>
# - Returns a string in HTML format.
0x - Returns a string in Perl format.
&h - Returns a string in VB format.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Sun 20 Oct 2002 09:45 PM (UTC)
Message
What are you planning to do with this colour? Try using world.RGBColourToName - this converts a colour code to a name, eg. "red", or if not in the list, "#FFE4E1" (for instance). Either case is usable directly in HTML (best to put it in quotes).

- Nick Gammon

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

Posted by Shadowfyr   USA  (1,790 posts)  Bio
Date Reply #2 on Mon 21 Oct 2002 01:42 AM (UTC)

Amended on Mon 21 Oct 2002 02:12 AM (UTC) by Shadowfyr

Message
Doh.. Ok.. Didn't see that. lol
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.


8,704 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.