You've got binary in my HTML...

Posted by Shadowfyr on Sun 20 Oct 2002 09:35 PM — 3 posts, 11,287 views.

USA #0
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.
Amended on Sun 20 Oct 2002 10:16 PM by Shadowfyr
Australia Forum Administrator #1
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).
USA #2
Doh.. Ok.. Didn't see that. lol