Console

DevTools, the api object in the console, a few commands to try, hooks, reloadMods and Ctrl+Shift+R.

The DevTools console runs API calls without a mod folder. Console code does not run again after a restart.

Open the Console#

F12 toggles DevTools in every build, including Steam builds. The --devtools launch flag opens DevTools at startup; on Steam, add it to the game's Launch Options. Open the Console tab.

Verify the API#

js
const api = window.SubwayBuilderAPI;
api.version; // "1.0.0"

version is a fixed string; it does not track the game version.

Try Some Commands#

Check Game State#

js
api.gameState.getBudget(); // number
api.gameState.getStations().length;
api.gameState.getRoutes();
api.gameState.getCurrentDay();

Modify Game State#

js
api.actions.setMoney(10_000_000_000);
api.actions.setPause(true);
api.actions.setSpeed('ultrafast');

Add a Custom City#

js
api.registerCity({
    name: 'Montreal',
    code: 'MTL',
    country: 'CA',
    initialViewState: { zoom: 13.5, latitude: 45.5017, longitude: -73.5673, bearing: 0 },
});

The city appears in the city picker. It has no data files, so it is a listing only; Custom cities covers the data. Console code has no mod context: the city is identified by its bare code and a warning says so.

Show a Notification#

js
api.ui.showNotification('Hello from the console', 'success');

Listen for Events#

Hooks work from the console. Keep the return value to stop the callback:

js
const stop = api.hooks.onDayChange((day) => console.log(`Day ${day}`));
stop();

One difference from a mod script: console code has no mod context. A city registered here logs a warning that it was registered without mod context, and storage.get logs [Modding API] storage.get called outside of mod context (storage.set logs the same with storage.set).

Explore the API#

Type api. or api.gameState. and the console's autocomplete lists the members. The API reference has one page per namespace.

Reload#

js
await api.reloadMods();

`reloadMods` clears every registered hook callback, including ones registered from the console, and re-runs every enabled mod script. Console-registered callbacks are not re-registered. Ctrl+Shift+R (Cmd+Shift+R on macOS) and the Reload Mods button the Mod Manager shows after a toggle call the same function. Debugging lists what is cleared and kept.

Move to a File#

Code that has to survive a restart goes into a mod folder. First mod has the skeleton.