First Mod
Create a proper mod with manifest.json
Now that you've experimented with the API in the console, let's create a proper mod that can be installed and shared.
Create the Mod Folder#
- Navigate to your mods folder (see Getting Started)
- Create a new folder for your mod:
mods/my-first-mod/
Add manifest.json#
Create manifest.json in your mod folder:
json
{
"id": "com.yourname.my-first-mod",
"name": "My First Mod",
"description": "My first Subway Builder mod!",
"version": "1.0.0",
"author": {
"name": "Your Name"
},
"main": "index.js"
}Manifest fields:
| Field | Required | Description |
|---|---|---|
id | Yes | Unique identifier (use reverse domain notation) |
name | Yes | Display name shown in the mod manager |
description | No | Short description of what your mod does |
version | Yes | Semantic version number |
author.name | Yes | Your name or username |
main | Yes | Entry point JavaScript file |
Add index.js#
Create index.js with your mod code:
javascript
// My First Mod for Subway Builder
(function () {
const api = window.SubwayBuilderAPI;
// Log when mod loads
console.log('[My First Mod] Loaded!');
// Show a notification when the game starts
api.hooks.onGameInit(() => {
api.ui.showNotification('My First Mod is active!', 'success');
});
// Give a bonus every 100 days
api.hooks.onDayChange((day) => {
if (day % 100 === 0) {
api.actions.addMoney(1_000_000, 'bonus');
api.ui.showNotification(`Day ${day} bonus: $1,000,000!`, 'success');
}
});
// Celebrate station milestones
let stationCount = 0;
api.hooks.onStationBuilt((station) => {
stationCount++;
if (stationCount === 10) {
api.ui.showNotification('10 stations! Keep growing!', 'success');
}
});
})();Enable the Mod#
- Restart Subway Builder (or use hot reload)
- Go to Settings > Mods
- Find "My First Mod" in the list
- Toggle it ON
- The mod is now active!
Mod Structure#
Your mod folder should look like this:
mods/
βββ my-first-mod/
βββ manifest.json
βββ index.jsBest Practices#
Wrap in IIFE#
Always wrap your mod code in an Immediately Invoked Function Expression (IIFE) to avoid polluting the global scope:
javascript
(function () {
// Your mod code here
})();Use a Prefix for Logging#
Add a prefix to your console logs so they're easy to identify:
javascript
console.log('[My Mod] Something happened');Handle Errors Gracefully#
Wrap risky operations in try-catch:
javascript
try {
// Risky operation
} catch (error) {
console.error('[My Mod] Error:', error);
}Check API Availability#
Always check if the API is available before using it:
javascript
if (!window.SubwayBuilderAPI) {
console.error('[My Mod] SubwayBuilderAPI not found!');
return;
}Next Steps#
- Electron Setup - Learn about hot reload and mod management
- Hooks - React to game events
- UI Customization - Add custom UI elements