Difference between revisions of "Print"

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
imported>Fredg1
m
 
(11 intermediate revisions by 5 users not shown)
Line 5: Line 5:
 
FunctionPage|
 
FunctionPage|
 
name={{#var:name}}|
 
name={{#var:name}}|
function_category=Miscellaneous|
 
  
 
function1={{Function|
 
function1={{Function|
Line 23: Line 22:
 
parameter2={{Param|string|color}}|
 
parameter2={{Param|string|color}}|
 
p1desc={{Pspan|message}} is the text to print|
 
p1desc={{Pspan|message}} is the text to print|
p2desc={{Pspan|color}} is an (optional) html color name or code|
+
p2desc={{Pspan|color}} is an html color name or code|
 
}}|
 
}}|
 +
function_description=Print the specified text {{pspan|message}} to the CLI. If the optional {{pspan|color}} parameter is specified and a valid html color code or entity, it will print in that color. See the [http://www.w3.org/TR/CSS21/syndata.html#color-units CSS 2.1 color specification] for a description of valid color syntax and keywords.|
  
function_description=Print the specified text {{pspan|message}} to the CLI. If the optional {{pspan|color}} parameter is specified and a valid html color code or entity, it will print in that color.|
+
code1={{CodeSample|
 +
title=Code Sample|
 +
description=Prints stuff in color and black. Note that it prints black twice: first and last.|
 +
code=
 +
<syntaxhighlight>
 +
print("This is black.");
 +
foreach color in $strings[blue, green, olive, darkorange, magenta, black]
 +
  print("This is "+color+".", color);
 +
</syntaxhighlight>
 +
}}|
  
needscode=yes|
 
  
see_also={{SeeAlso|logprint|print_html}}|
+
see_also={{SeeAlso|dump|logprint|print_html|chat_notify}}|
cli_equiv=The CLI commands "fprint," "echo" and "fecho" have similar functionality, minus the color option.|
+
cli_equiv=The CLI commands "fprint," "echo" and "fecho" have similar functionality, minus the color option. However, "cecho" (also "colorecho") does have this option for color.|
special= Using an invalid color name or code can cause odd colors to be chosen.|
+
special=A list of common color commands that can be used: olive, yellow, orange, gray, fuchsia, red, white, silver, teal, navy, blue, maroon, purple. <br> More advance colors can be used by entering their Hexadecimal code as the string. <br>Using an invalid color name or code can cause odd colors to be chosen; see the [[Talk:Print|Talk Page]] for details.
 +
<br />As of r8638, attempting to print a string beginning with a slash(/) will cause KoLmafia to print a blank line instead. To avoid this behavior, you must specify the second argument for the text color. Any color will do, and even a blank string (<code>""</code>) will work.
 +
|
 
}}
 
}}
{{RFI|How does color selection work when the specified color name / entity is invalid?|Didn't print() used to echo on the Adventuring status line? Is the absence of such behavior intentional?}}
+
 
 +
[[Category:Miscellaneous Functions]]

Latest revision as of 23:20, 20 September 2020

Function Syntax

void print(string message )

void print(string message ,string color )

  • message is the text to print
  • color is an html color name or code

Print the specified text message to the CLI. If the optional color parameter is specified and a valid html color code or entity, it will print in that color. See the CSS 2.1 color specification for a description of valid color syntax and keywords.

Code Sample

Prints stuff in color and black. Note that it prints black twice: first and last.

print("This is black.");
foreach color in $strings[blue, green, olive, darkorange, magenta, black]
   print("This is "+color+".", color);

CLI Equivalent

The CLI commands "fprint," "echo" and "fecho" have similar functionality, minus the color option. However, "cecho" (also "colorecho") does have this option for color.

See Also

dump() | logprint() | print_html() | chat_notify()

Special

A list of common color commands that can be used: olive, yellow, orange, gray, fuchsia, red, white, silver, teal, navy, blue, maroon, purple.
More advance colors can be used by entering their Hexadecimal code as the string.
Using an invalid color name or code can cause odd colors to be chosen; see the Talk Page for details.
As of r8638, attempting to print a string beginning with a slash(/) will cause KoLmafia to print a blank line instead. To avoid this behavior, you must specify the second argument for the text color. Any color will do, and even a blank string ("") will work.