Talk:Print: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>Heeheehee
No edit summary
imported>Heeheehee
m Added in more rules. Blah.
Line 9: Line 9:


Okay. I think I've fully worked out the logic for the numbers.<br />
Okay. I think I've fully worked out the logic for the numbers.<br />
0: If there's a # in front, take the first 6 digits that follow.
1: Remove all zeroes in the front of the string (e.g. "#00 00 F0 00 00" becomes "F0 00 00").<br />
1: Remove all zeroes in the front of the string (e.g. "#00 00 F0 00 00" becomes "F0 00 00").<br />
2: If length > 7, replace the whole thing with "#00 00 00" (i.e. black).<br />
2: If length > 7, replace the whole thing with "#00 00 00" (i.e. black).<br />
Line 17: Line 18:
This ASH function might help with understanding:
This ASH function might help with understanding:
   string color (string input) {
   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);
     while(index_of(input, "0") == 0) input = substring(input, 1);
     if(length(input)>7) return "000000";
     if(length(input)>7) return "000000";

Revision as of 18:03, 14 March 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.
0: If there's a # in front, take the first 6 digits that follow. 1: Remove all zeroes in the front of the string (e.g. "#00 00 F0 00 00" becomes "F0 00 00").
2: If length > 7, replace the whole thing with "#00 00 00" (i.e. black).
3: If length = 7, remove the first character (e.g. the red displayed from "#ff0 00 00" is actually "#f0 00 00").
4: 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).
5: Pass the resultant value as your color.

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)