@rbxts/jsnatives
error
Outputs an error message to the console with distinctive formatting to indicate an error condition.
Signature
function error(...args: unknown[]): void
Description
The console.error
method prints one or more values to the console, typically with red text or special styling to distinguish error messages from regular log output. Like console.error
, it supports string formatting when the first argument is a string, and automatically inspects objects.
Parameters
...args
: A list of values to output to the console as an error. If the first argument is a string, it can contain format specifiers.
Return value
- None (void).
Examples
Basic usage
// Logging a simple stringconsole.error("Hello world");// Outputs: Hello world (with indentation)
// Logging with string formattingconsole.error("Player %s has score %d", "Alex", 42);// Outputs: Player Alex has score 42 (formatted string with indentation)
// Logging numbers without formattingconsole.error(42);// Outputs: 42 (with indentation)
String formatting
// Using string format specifiers (like Lua's string.format)console.error("Pi is approximately %.2f", 3.14159);// Outputs: Pi is approximately 3.14
// Multiple argumentsconsole.error("Player: %s, Level: %d, Active: %s", "John", 5, true);// Outputs: Player: John, Level: 5, Active: true
// Percent signconsole.error("Progress: %d%%", 75);// Outputs: Progress: 75%
Logging objects
// Logging an object (uses inspection)const player = { name: "PlayerOne", level: 5, health: 100, inventory: ["sword", "shield", "potion"]};
console.error(player);// Outputs an inspected representation without indentation:// {name: "PlayerOne", level: 5, health: 100, inventory: ["sword", "shield", "potion"]}
Logging arrays
// Logging an arrayconst items = ["apple", "banana", "orange"];console.error(items);// Outputs inspected array without indentation:// ["apple", "banana", "orange"]