Documentation Index
Fetch the complete documentation index at: https://mintlify.com/OpenRCT2/OpenRCT2/llms.txt
Use this file to discover all available pages before exploring further.
The console object provides methods for logging output and interacting with the stdout console. This is useful for debugging plugins and displaying information.
Methods
log()
Logs a message to the console with optional additional parameters.
Additional values to log.
console.log('Hello, OpenRCT2!');
console.log('Park rating:', park.rating);
console.log('Multiple values:', 1, 2, 3);
console.log('Object:', { name: 'Test', value: 42 });
Simple Logging
Debugging Data
Error Tracking
// Log simple messages
console.log('Plugin loaded successfully');
console.log('Current API version:', context.apiVersion);
// Log complex data structures
const ride = map.getRide(0);
console.log('Ride data:', {
id: ride.id,
name: ride.name,
excitement: ride.excitement,
intensity: ride.intensity
});
// Log errors and warnings
try {
// Some risky operation
const result = performOperation();
console.log('Operation succeeded:', result);
} catch (error) {
console.log('ERROR:', error);
}
Usage Examples
Basic Logging
Log plugin initialization and status messages:
registerPlugin({
name: 'My Plugin',
version: '1.0.0',
authors: ['Author'],
type: 'remote',
licence: 'MIT',
targetApiVersion: 77,
main: () => {
console.log('My Plugin initialized');
console.log('API Version:', context.apiVersion);
console.log('Game Mode:', context.mode);
}
});
Debugging Game State
Log game state information for debugging:
function logParkStatus() {
console.log('=== Park Status ===');
console.log('Name:', park.name);
console.log('Cash:', park.cash);
console.log('Rating:', park.rating);
console.log('Guests:', park.guests);
console.log('Rides:', map.numRides);
console.log('Date:', `${date.year}-${date.month}-${date.day}`);
}
// Log status every in-game day
context.subscribe('interval.day', () => {
logParkStatus();
});
Event Monitoring
Log events as they occur:
// Monitor guest generation
context.subscribe('guest.generation', (e) => {
console.log('Guest generated with ID:', e.id);
});
// Monitor network activity
context.subscribe('network.join', (e) => {
const player = network.getPlayer(e.player);
console.log('Player joined:', player.name);
});
context.subscribe('network.leave', (e) => {
console.log('Player left:', e.player);
});
Log performance metrics:
let tickCount = 0;
let lastLog = Date.now();
context.subscribe('interval.tick', () => {
tickCount++;
const now = Date.now();
if (now - lastLog >= 1000) {
console.log('Ticks per second:', tickCount);
tickCount = 0;
lastLog = now;
}
});
Action Logging
Log game actions for debugging:
context.subscribe('action.execute', (e) => {
console.log('Action executed:', e.action);
console.log('Player:', e.player);
console.log('Arguments:', e.args);
if (e.result.error) {
console.log('ERROR:', e.result.errorMessage);
} else {
console.log('Success! Cost:', e.result.cost);
}
});
Advanced Logging
Conditional Logging
Log only when certain conditions are met:
const DEBUG = true;
function debugLog(message, ...params) {
if (DEBUG) {
console.log('[DEBUG]', message, ...params);
}
}
debugLog('This is a debug message');
debugLog('Value:', 42);
Categorized Logging
Organize logs by category:
const Logger = {
info: (msg, ...args) => console.log('[INFO]', msg, ...args),
warn: (msg, ...args) => console.log('[WARN]', msg, ...args),
error: (msg, ...args) => console.log('[ERROR]', msg, ...args),
debug: (msg, ...args) => console.log('[DEBUG]', msg, ...args)
};
Logger.info('Plugin started');
Logger.warn('Low park rating:', park.rating);
Logger.error('Failed to load ride');
Logger.debug('Variable value:', someValue);
Timestamped Logging
Add timestamps to log messages:
function log(message, ...params) {
const timestamp = new Date().toISOString();
console.log(`[${timestamp}]`, message, ...params);
}
log('Event occurred');
log('Guest count:', park.guests);
Tips and Best Practices
Performance: Excessive logging can impact game performance. Use logging judiciously, especially in frequently called functions like tick handlers.
Development vs Production: Consider using a debug flag to enable/disable detailed logging between development and production builds.
Sensitive Data: Avoid logging sensitive information like player passwords or personal data in multiplayer environments.
Console Output Location
Console output appears in different locations depending on how OpenRCT2 is running:
- Windows GUI: Output appears in the console window if started with console enabled
- Windows Console: Output appears directly in the terminal
- Linux/Mac: Output appears in the terminal where OpenRCT2 was launched
- Server: Output appears in the server console/logs
Legacy Console Commands
executeLegacy()
This method is deprecated and should not be used in new plugins. It exists only for servers to continue using old commands.
Executes a command using the legacy console REPL.
The command and arguments to execute.
// Not recommended for use in plugins
console.executeLegacy('get park_rating');
See Also
- Context API - For game state and events
- UI API - For displaying information in the game UI