Print

From ZDoom Wiki
Jump to navigation Jump to search

void Print(item(s));

Usage

Print will print something to the activating player's screen. This can be text or variables or any combination of the two. Note that Print is fairly inflexible (there is no way to modify the position on screen or the time the message stays up) so you may wish to consider using HudMessage instead.

Print will only display for the activator of the script, so if another player activates a script with a Print statement in it, then it will only be displayed for that other player and you will not see it. For printing to all players, see PrintBold. If a script is activated by something that is not a player at all then the message will simply not be displayed anywhere.

Note: Do not use Print as a debug tool. In many scripting and programming languages it is quite common to check that a complex code executes properly by MiniWikipediaLogoIcon.pngtracing its operation with print or printf statements; in ACS, you need to use Log or PrintBold or the trace will possibly not display at all, making it look like the script does not actually run.


Cast type

Item syntax
<cast type>:<expression>

The string can be built up of any number of these items, separated by commas. The cast type is used to differentiate what type of data is being displayed. The table below shows the available options.

cast type description
a prints a character array. (Ex.: a:arrayname)

a:(arrayname[, int starting_index[, int size_limit]]) prints the character array specified by arrayname starting from starting_index, printing only up to size_limit characters.

b binary number
c character
d decimal number (integer, same as i)
f fixed point number
i decimal number (integer, same as d)
k prints the key(s) (up to 2) that the player has bound to the specified command. (Ex.: k:"+use")
l localized string from LANGUAGE
n name, expression could be:
  • PRINTNAME_LEVELNAME - Prints the level name (e.g., "Entryway").
  • PRINTNAME_LEVEL - Prints the map lump name (e.g., "MAP01").
  • PRINTNAME_SKILL - Prints the skill name (e.g., "Hurt me plenty").
  • PRINTNAME_NEXTLEVEL - Prints the map lump name of the next map.
  • PRINTNAME_NEXTSECRET - Prints the map lump name of the next secret map.


Using 0 as expression prints the name of the activator (a tag name if the activator isn't a player, player name otherwise). Values greater than 0 will print the name of the n-th player (one-based).

s string
x hexadecimal number

Escape sequence

The other special characters to note are escaped characters. A new line is started with \n. A backslash character is placed with \\, except there is no graphic for backslash by default in Doom.

Escape sequences are contained within a string. They begin with the backslash character: '\'.

Available escape sequences, as handled by the strbin function in cmdlib.cpp, include:

sequence description
\OOO Inserts a character by the octal value of its ASCII code. OOO must be a valid three-digit octal number.
\a Beep—no function in engine
\b Backspace—no function in engine
\cCODE Beginning of a color escape sequence, see below for color codes.
\f Form feed—no function in engine
\n New line
\r Carriage return—no function in engine
\t Tabulation—no function in engine
\v Vertical tabulation—no function in engine
\xXX Inserts a character by the hexadecimal value of its ASCII code. XX must be a valid two-digit hexadecimal number.
\" Double quotations. This is the only way to insert double quotes properly into the string, since they otherwise terminate without the backslash.

Colors

You can add color to lines of text by using the \cX escape code, where X is one of the codes from the table below. (ZScript constants are for ZScript only and are not supported by Print()). The following text colors are supported:

ZScript constant code color Zscript Constant code color
CR_BRICK a ██ reddish brick CR_LIGHTBLUE n ██ light blue
CR_TAN b ██ tan CR_CREAM o ██ cream
CR_GREY or CR_GRAY c ██ gray CR_OLIVE p ██ olive
CR_GREEN d ██ green CR_DARKGREEN q ██ dark green
CR_BROWN e ██ brown CR_DARKRED r ██ dark red
CR_GOLD f ██ gold CR_DARKBROWN s ██ dark brown
CR_RED g ██ red CR_PURPLE t ██ purple
CR_BLUE h ██ blue CR_DARKGRAY u ██ dark gray
CR_ORANGE i ██ orange CR_CYAN v ██ cyan
CR_WHITE j ██ white CR_ICE w ██ ice
CR_YELLOW k ██ yellow CR_FIRE x ██ fire
CR_UNTRANSLATED l use original colors CR_SAPPHIRE y ██ sapphire
CR_BLACK m ██ black CR_TEAL z ██ teal
- Default color for Print messages * Default color for chat messages
+ Default color for PrintBold messages ! Default color for team chat messages

The color will revert back to the default message color at the end of every line, therefore a \cX escape must be on every line where color is needed. Using \c- also clears color, so that printed messages (obituaries, pickup messages, etc.) with player names within them will retain their individual colors.

For example,

print(s:"\cgRoses are red\n\chViolets are blue\n\cjSilver for me\n\cfGold for you");

will be displayed as Printcolor.png.

You can also use the syntax \c[colorname], where colorname is a name of a color as defined in the TEXTCOLO lump.

For example,

print(s:"\c[Green]This is green");

Would print

This is green

But on some versions of the engine this variant will not print only one symbol after escape sequence to stdout (not in in-game console), e. g. previous example on the OS console will be shown as "GreenThis is green".

Examples

Some basic uses of print.

script 1 (void)
{
	int x = 10;
	Print(s:"This is a string");   //prints "This is a string"
	Delay(35*5);
	
	Print(d:x);   //prints "10"
	Delay(35*5);
	
	Print(s:"This is x: ", d:x);   //prints "This is x: 10"
	Delay(35*5);
	
	Print(s:"I need ", d:x, s:" shells");   //prints "I need 10 shells"
}

Another example of a (potentially) useful debugging script which continually updates the player on their current game coordinates:

script 1 ENTER
{
	While(TRUE)
	{
		Print(f:GetActorX(0), s:" : ",
			f:GetActorY(0));
		Delay(10);
	}
}

This example tells the user to press whatever key they have bound to +use:

script 1 (void)
{
       Print(s:"Press ", k:"+use", s:" to use this ladder.");
}