Skip to content

Utility functions

distance(a, b)

Calculate distance between two positions.

Parameters:

  • a: Vec2 - First position
  • b: Vec2 - Second position

Returns: number - Distance in nautical miles

Example:

javascript
const ac1 = traffic.byCallsign("AAL123");
const ac2 = traffic.byCallsign("DAL456");

if (ac1 && ac2) {
  const dist = distance(ac1.pos, ac2.pos);
  log(`Separation: ${dist.toFixed(1)}nm`);

  if (dist < 5) {
    log("Losing lateral separation!");
  }
}

headingTo(from, to)

Calculate heading from one position to another.

Parameters:

  • from: Vec2 - Starting position
  • to: Vec2 - Target position

Returns: number - Heading in degrees (0-360)

Example:

javascript
const ac = traffic.byCallsign("AAL123");
const fix = fixes.get("KMART");

if (ac && fix) {
  const hdg = headingTo(ac.pos, fix.pos);
  log(`Heading to KMART: ${hdg.toFixed(0)}°`);

  // Check if aircraft is on course
  const hdgDiff = Math.abs(ac.hdgDeg - hdg);
  if (hdgDiff > 10) {
    log(`${ac.cs} is ${hdgDiff.toFixed(0)}° off course`);
  }
}

flightlevel(fl) / fl(fl)

Convert flight level to feet.

Parameters:

  • fl: number - Flight level (e.g., 350 for FL350)

Returns: number - Altitude in feet

Example:

javascript
// These are equivalent:
aircraft.climb(flightlevel(350));
aircraft.climb(fl(350));  // Shorter alias
aircraft.climb(35000);    // Direct feet

// Useful for calculations
const targetFL = 350;
aircraft.climb(fl(targetFL));  // 35,000 feet

Activity panel functions

log(message)

Output messages to the activity panel.

Parameters:

  • message: string - Message to display

Examples:

javascript
log("Normal message");
log(`Aircraft ${ac.cs} at FL${ac.altFL}`);
log(`Warning: Conflict detected`);
log(`Separation: ${dist.toFixed(1)}nm`);