Elevator visualization will render here
ElevatorAPI Reference
Your init(elevators, floors, log) function receives an array of elevator objects, a floors array, and a log function.
Use methods and events on each elevator to control it.
Methods
- elevator.goToFloor(floorNumber)
- Command the elevator to travel to the given floor (0-indexed). Sets the destination immediately, replacing any current destination. Call from event handlers to redirect mid-trip.
- elevator.stop()
- Clear the elevator's destination and stop at the nearest floor.
Properties & Getters
- elevator.currentFloor
- The floor the elevator is currently at (integer). While moving, this is the last floor it was at.
- elevator.getPressedFloors()
- Returns an array of floor numbers that passengers have pressed inside the elevator (internal buttons).
- elevator.getActiveFloorButtons()
-
Returns an array of objects for all currently active hall call buttons.
Directional floors return
{ floor, direction }; single-button floors return{ floor }.
Events
Register listeners with elevator.on(event, callback).
Remove with elevator.off(event, callback).
- 'idle'
- Fired when the elevator has no pending destinations and is ready for a new command.
-
elevator.on('idle', () => { ... }) - 'floor_button_pressed' → (floorNum, direction?)
-
Fired when a hall call button is pressed at a floor. On directional floors,
directionis"up"or"down". On single-button floors, direction is omitted. -
elevator.on('floor_button_pressed', (floorNum, direction) => { ... }) - 'passing_floor' → (floorNum, direction)
-
Fired when the elevator passes a floor while moving.
directionis"up"or"down". Not fired for the destination floor. -
elevator.on('passing_floor', (floorNum, direction) => { ... }) - 'stopped_at_floor' → (floorNum)
- Fired when the elevator arrives at its destination and begins loading/unloading passengers.
-
elevator.on('stopped_at_floor', (floorNum) => { ... })
Floors Array
- floors[i].level
- The floor number (0-indexed).
- floors[i].buttonCallState
- Boolean — whether the hall call button is active (single-button floors only).
- floors[i].buttonUpState / buttonDownState
- Boolean — whether the up/down hall call button on this floor is currently active (directional floors only).
- floors[i].waitingPassengers
- The number of passengers currently waiting on this floor.
Logging
Your init function receives a third argument:
a log function for printing messages to the Event Log panel.
- log(...args)
- Print a custom message to the Event Log panel. Accepts any number of arguments, which will be joined by spaces.
-
log("current floor:", elevator.currentFloor)
Time:
00:00
Delivered:
0/0
Avg Wait:
—
Avg Ride:
—
Max Wait:
—
○
Avg Wait ≤
—
○
Avg Ride ≤
—