Talk:Print: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
No edit summary
imported>PhilmASTErpLus
Browsing through KoLmafia tells me it uses the Swing HTML parser, which probably explains why it doesn't understand colornames like "AliceBlue".
 
(3 intermediate revisions by 3 users not shown)
Line 17: Line 17:
# Pass the resultant value as your color.
# Pass the resultant value as your color.


:Perhaps KoLmafia uses some variant of the color parsing/interpreting scheme used in CSS, as it apparently supports the syntax <code>"rgb(148, 0, 211)"</code> and <code>"rgb(148 0 211)"</code>. We would need to look at the source code to confirm this... --[[User:PhilmASTErpLus|PhilmASTErpLus]] 17:00, 16 July 2010 (UTC)
:: IIRC, it passes it directly to HTML -- '''print(a,b)''' is functionally equivalent to '''print_html("&lt;font color='"+b+"'&gt;"+a+"&lt;/font&gt;")'''. --[[User:Heeheehee|Heeheehee]] 17:18, 16 July 2010 (UTC)
:::It seems to use the native Swing HTML parser, which does not understand many unofficial colornames (see [http://www.w3.org/TR/CSS21/syndata.html#color-units CSS 2.1 color specification] and [http://www.w3.org/TR/html401/types.html#h-6.5 HTML 4.01 color specification] for color syntax. W3schools has a [http://www.w3schools.com/css/css_colornames.asp list of non-standard color names] supported by all major browsers.). --[[User:PhilmASTErpLus|PhilmASTErpLus]] 04:32, 17 July 2010 (UTC)
This ASH function might help with understanding:
This ASH function might help with understanding:
   string color (string input) {
   string color (string input) {
Line 33: Line 36:


I was referring to the version of such that is also shown on the login / logout screen, which I feel is relevant as there isn't a good way to give feedback on a logout script otherwise (currently, I have a logout script that uses a user_confirm() for the clunky purpose of getting around this). If there's a way I'm unaware of to deal with this, that would be fine; but otherwise I'd like to know if print() could once again place text there, or if I'm mis-remembering. --[[User:StDoodle|StDoodle (#1059825)]] 00:53, 30 April 2010 (UTC)
I was referring to the version of such that is also shown on the login / logout screen, which I feel is relevant as there isn't a good way to give feedback on a logout script otherwise (currently, I have a logout script that uses a user_confirm() for the clunky purpose of getting around this). If there's a way I'm unaware of to deal with this, that would be fine; but otherwise I'd like to know if print() could once again place text there, or if I'm mis-remembering. --[[User:StDoodle|StDoodle (#1059825)]] 00:53, 30 April 2010 (UTC)
:Ah. I can see why you'd want that. Post it in a feature request on the mafia forums. That's the proper place for it. Then if your desire is granted we can update this page. :D --[[User:Bale|Bale]] 02:07, 30 April 2010 (UTC)

Latest revision as of 04:32, 17 July 2010

Re: "How does color selection work when the specified color name / entity is invalid?"
It returns with the default, black. That is, unless '> ash print("Hello world!","apple-orange");' returns a color that looks really close to black. (No, I'm not color-blind. It returns black. Even for faulty entities, like "42".)
Edit: Apparently it doesn't recognize somewhat uncommon colors, like "lavender". --Heeheehee 06:47, 10 March 2010 (UTC)

That's true for named colors, but for numbers it appears to interpret some part of the number and chop the rest off; it was just a bit more than I wanted to look up in the moment. For instance, if you supply "#ff00000" (which is red with an extra 0), it used red; the "#" appears to make it choose the first 6 digits. However, you can leave off the "#" and it still works as expected with a 6-digit or 3-digit number; but anything else seems to be a weird substring match for which I can't find the logic.--StDoodle 13:26, 10 March 2010 (UTC)


Okay. I think I've fully worked out the logic for the numbers.

  1. If there's a # in front, take the first 6 digits that follow.
  2. If length = 6, skip to the last step.
  3. Remove all zeroes in the front of the string (e.g. "#00 00 F0 00 00" becomes "F0 00 00").
  4. If length > 7, replace the whole thing with "#00 00 00" (i.e. black).
  5. If length = 7, remove the first character (e.g. the red displayed from "#ff0 00 00" is actually "#f0 00 00").
  6. If length < 6, add zeroes to the front until length = 6 (e.g. "#42" becomes "#00 00 42", which looks pretty close to black -- hence my earlier misunderstanding).
  7. Pass the resultant value as your color.
Perhaps KoLmafia uses some variant of the color parsing/interpreting scheme used in CSS, as it apparently supports the syntax "rgb(148, 0, 211)" and "rgb(148 0 211)". We would need to look at the source code to confirm this... --PhilmASTErpLus 17:00, 16 July 2010 (UTC)
IIRC, it passes it directly to HTML -- print(a,b) is functionally equivalent to print_html("<font color='"+b+"'>"+a+"</font>"). --Heeheehee 17:18, 16 July 2010 (UTC)
It seems to use the native Swing HTML parser, which does not understand many unofficial colornames (see CSS 2.1 color specification and HTML 4.01 color specification for color syntax. W3schools has a list of non-standard color names supported by all major browsers.). --PhilmASTErpLus 04:32, 17 July 2010 (UTC)

This ASH function might help with understanding:

 string color (string input) {
    if(index_of(input, "#" && length(input)>6) == 0) return substring(input, 0, 6);
    if(length(input) == 6) return input;
    while(index_of(input, "0") == 0) input = substring(input, 1);
    if(length(input)>7) return "000000";
    if(length(input)==7) return substring(input, 1);
    while(length<6) input = "0" + input;
    return input;
 }

(is that too much string manipulation?) --Heeheehee 02:44, 14 March 2010 (UTC)

Re: the former RFI (echoing print statements to the adventuring status line)

I was referring to the version of such that is also shown on the login / logout screen, which I feel is relevant as there isn't a good way to give feedback on a logout script otherwise (currently, I have a logout script that uses a user_confirm() for the clunky purpose of getting around this). If there's a way I'm unaware of to deal with this, that would be fine; but otherwise I'd like to know if print() could once again place text there, or if I'm mis-remembering. --StDoodle (#1059825) 00:53, 30 April 2010 (UTC)

Ah. I can see why you'd want that. Post it in a feature request on the mafia forums. That's the proper place for it. Then if your desire is granted we can update this page. :D --Bale 02:07, 30 April 2010 (UTC)