PrintToConsole

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search

A command for Oblivion Script Extender

Syntax:

PrintToConsole "Message text", [var1], [var2], etc
PrintC "Message text", [var1], [var2], etc

Prints a formatted string to console. Uses the same syntax as Message and MessageBox. Mainly useful for debugging purposes.

Notes[edit | edit source]

  • This function works in conjunction with the console function ToggleDebugText. When PrintToConsole is called while TDT is active, console messages will be visible during normal gameplay. Useful for debugging when a lot of messages need to be displayed.
  • If using an OBSE version prior to v0013, GetInventoryObject and GetNumItems will also return messages to the console (1 message for each item). As the number of console lines is limited, use caution with these and PrintToConsole.
  • You can increase the number of lines in the console by increasing the iConsoleVisibleLines setting in the config file, found at
..\Documents and Settings\"User Name"\My Documents\My Games\Oblivion\Oblivion.ini
  • As of v0014, PrintToConsole accepts the "EX" formatting specifiers.
  • With v0015 it is possible to print colored console text via the %a identifier. Use 2 to turn blue text on and 3 to turn it off.
PrintToConsole "I like to eat %ablue%aberries" 2 3

Style Suggestions[edit | edit source]

For modders using PrintToConsole to print debug info in a 'released' version of a mod, it is a good idea to add an identifying tag to the beginning of the text. For example, if the mod is named Random Modder's Mod, do the following:

printc "RMM: some debug info goes here"

If the mod is complex with several scripts running simultaneously, it can be a good idea to identify the script as well, in order to easily identify where a message is coming from, such as:

printc "RMM|OptionsMenu: the player closed the menu"

Another option (not mutually exclusive of the preceding) is to identify messages from quest scripts and quest stage result scripts by prefixing them with a short version of the name of the quest. For instance, if Random Modder's Mod has quests RMM Quest 1 and RMM Quest 2, the message might be might be:

printc "RMMQ2: Player defeated secondary boss"

For quest stage result scripts, it can be useful to include the stage number in the prefix, for example:

printc "RMMQ2.115 Player obtained location of cave from town guard"

for Stage 115's result script. This more elaborate prefixing is most useful for large mods with many scripts and multiple quests. Also, carefully-formatted messages can be especially useful when a mod's beta testers are using one of the various console log capture utilities to keep their logs as text files. By following the above suggestions you help the end-user of your mod determine where possible bugs are occurring, and they will be able to distinguish which mod is printing the various console messages that show up when running multiple mods.

Displaying Variables[edit | edit source]

Formatting notation[edit source]

%.2f - This means format the variable with 2 decimal places.

%.0f - This will format the variable with 0 decimal places, so is the normal choice for integers.

%5.0f - The number in front of the point specifies the minimum width of the number. In this case, there will always be enough space in front of the number for 5 digits:

Number    12 wins
Number  1234 wins

Formating switches[edit source]

The following formatting switches can be used in Oblivion. Put them in any sequence right after the '%'

Switch Function
+ Display + in front of positive numbers
<Space> Leave a leading space in front of positive numbers
- Use left-aligned formation instead of right alligned.
0 The filling-char used for formatting is '0' instead of ' '

Other Functions[edit source]

%g - This usually works just like "%.0f", displaying 0 decimal places. When the number is 1000000 or larger, though, the game displays it in scientific notation (1E+006)

%.3e - Shows numbers in scientific notation (123000 = 1.23E+005)

%% - Use this to display a percent-sign in the message


OBSE Format Specifiers[edit source]

In addition to the format specifiers supported by Oblivion's Message and MessageBox functions, OBSE functions understand additional specifiers (in alphabetic order).


%a - Prints the character corresponding to the specified ASCII code.

  • Passing codes for unprintable characters (such as 0) may have unpredictable (though occasionally useful) results.
  • Passing the code for a percent sign will most likely crash the game as literal percent signs must come in pairs.


%B - toggles blue text on for console output.

%b - toggles blue text off for console output.

  • Example: "%BBlue%b suede shoes": when printed to the console, the word "Blue" will be printed in blue text.


%c - Prints the specified component of the specified reference or object.

Takes two arguments - a reference variable set to the spell or faction, and an index. Behaves differently depending on the passed reference:
  • Faction: Prints the nth male rank title
  • Magic Item: Prints the nth Magic Effect
  • Prior to OBSE v0015, magic effects using actor values (such as Restore Agility) would not display the specific actor value.
  • Actor values may not display correctly for non-English versions of Oblivion.


%e – replaced by nothing.

  • Provides a workaround for the script compiler's refusal to accept an empty string as a command argument.
  • Example:
SetNameEx "" object    ; attempts to remove an object's name, but won't compile
SetNameEx "%e" object  ; sets the name to an empty string
  • Can be used outside of format strings. When included in any string literal, %e will be replaced by an empty string.


%i - Prints the FormID of the specified reference or object.

  • GOTCHA : as of v18, if a refVar is passed which points to a ref not loaded in memory %i will print 00000000 even if the refVar is not empty.


%k - Prints the name of the key for the specified DirectInput scancode, such as those used for IsKeyPressed2.


%n - Prints the name of the specified reference or object.

  • In OBSE versions prior to v0014a, %n can crash if the object's name contains a percent sign.


%p - Displays a pronoun based on the gender of the object parameter:

  • %po - objective (him, her, it)
  • %pp - possessive (his, her, its)
  • %ps - subjective (he, she, it)


%q - Prints a double quote character.

  • Can be used outside of format strings. When included in any string literal, %q will be replaced by a double quote

%r - Prints a carriage return, ending the current line and starting at the next.

  • Can be used outside of format strings. When included in any string literal, %r will be replaced by a carriage return.


%v - Prints the actor value (i.e. an attribute or skill) associated with the passed actor value code.


%x - Prints an integer in hexadecimal format.

An optional digit from 0-9 immediately following this specifier indicates the minimum width of the displayed value.
  • For example, MessageEx "%x4" 255 will display "00FF".


%z – Prints the contents of a string variable.

  • Example: sv_construct “The string is: %z” MyStringVar


%{...%} - Conditionally displays or omits the bracketed portion of the format string based on a boolean value. Accepts a variable - if the value of the variable is zero, all text and parameters up to the matching right bracket will be ignored. Otherwise the bracketed text will be displayed.

  • Example (should be single-line, line-breaks added for Wiki)
MBoxEX "Doom comes%{ for you%}. What will you do?
|Dig a hole, hide
%{|Find someone, offer as sacrifice|Find someone, use as shield%}
|Enjoy your final 15 minutes" bDisplay bDisplay

If bDisplay is 0 this will print out

   Doom comes. What will you do?
   [Dig a hole, hide]
   [Enjoy your final 15 minutes]

If bDisplay is 1 this will print out

   Doom comes for you. What will you do?
   [Dig a hole, hide]
   [Find someone, offer as sacrifice]
   [Find someone, use as shield]
   [Enjoy your final 15 minutes]
  • Note: When using GetButtonPressed with messageboxes that can have a variable number of buttons displayed using %{...%}, the return value will be relative to the actual number of buttons displayed and will not include buttons hidden by %{...%}.


See Also[edit | edit source]