Print

From ZDoom Wiki
Jump to: navigation, search

void Print(item(s));

Usage

Print will print something to the 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 an enemy (or another player) activates a script with a Print statement in it, then you will not see it. For printing to all players, see PrintBold.

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
f fixed point number
i decimal
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").


Using 0 as expression prints the name of the activator (a class 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(Verification needed)
\b Backspace (erases previous character)(Verification needed)
\cCODE Beginning of a color escape sequence, see below for color codes.
\f Clear string buffer(Verification needed)
\n New line
\r New line (Advisable to use \n)(Verification needed)
\t Tabulation
\v Vertical tabulation(Verification needed)
\xXX Inserts a character by the hexadecimal value of its ASCII code. XX must be a valid two-digit hexadecimal number.
\? Delete (erases next character)(Verification needed)
\↵ Ignore the "new line" separator. This can be used to split a long string on several lines in the script source code. Make sure there aren't any space or other invisible character after the backslash and before the end of the line, however.

Colors

You can add color to lines of text by using the \cX escape code. Replace X with the following letter to produce the desired color:

code color code color
a ██ reddish brick l use original colors
b ██ tan m ██ black
c ██ gray n ██ light blue
d ██ green o ██ cream
e ██ brown p ██ olive
f ██ gold q ██ dark green
g ██ red r ██ dark red
h ██ blue s ██ dark brown
i ██ orange t ██ purple
j ██ white u ██ dark gray
k ██ yellow v ██ cyan
- 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 textcolors lump.

For example,

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

Would print

This 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.");
}