Skip to main content
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.
message
any
The message to log.
optionalParams
any[]
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 });
// Log simple messages
console.log('Plugin loaded successfully');
console.log('Current API version:', context.apiVersion);

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);
});

Performance Monitoring

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.
command
string
required
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