Game Actions
Modify game state with action methods
Actions let your mod modify the game state. Use these to add money, control game flow, and more.
Important: Most actions use deferred execution (queueMicrotask) so they are safe to call from inside hooks like onDayChange. The action returns immediately, but the actual state change happens on the next microtask. This means you cannot read the updated state on the very next line ā use a hook like onMoneyChanged to react to the change instead.
Exception: issueBond, payBond, getBonds, and getTicketPrice execute synchronously because they return values. Avoid calling these from inside hooks if possible.
Money Actions#
setMoney#
Set the player's money to an exact amount. Triggers the onMoneyChanged hook if the value differs from the current balance.
window.SubwayBuilderAPI.actions.setMoney(10_000_000);addMoney#
Add money to the player's balance. The second parameter is optional and currently unused (reserved for future categorization).
window.SubwayBuilderAPI.actions.addMoney(1_000_000);
window.SubwayBuilderAPI.actions.addMoney(500_000);subtractMoney#
Subtract money from the player's balance. The second parameter is optional and currently unused (reserved for future categorization).
window.SubwayBuilderAPI.actions.subtractMoney(500_000);Game Flow Actions#
setPause#
Pause or resume the game.
// Pause the game
window.SubwayBuilderAPI.actions.setPause(true);
// Resume the game
window.SubwayBuilderAPI.actions.setPause(false);setSpeed#
Set the game speed.
// Available speeds: 'slow', 'normal', 'fast', 'ultrafast'
window.SubwayBuilderAPI.actions.setSpeed('fast');
window.SubwayBuilderAPI.actions.setSpeed('ultrafast');setTicketPrice#
Set the ticket price (fare). Also updates the default cost for new games.
window.SubwayBuilderAPI.actions.setTicketPrice(5);getTicketPrice#
Get the current ticket price. Returns number.
const price = window.SubwayBuilderAPI.actions.getTicketPrice();setSpeedMultiplier#
Modify how many game-seconds pass per real second for a given speed tier. Multipliers are always applied to the original base value, so calling this multiple times or across hot reloads will not compound ā it safely replaces the previous multiplier.
// Make "fast" speed 2x faster than default
window.SubwayBuilderAPI.actions.setSpeedMultiplier('fast', 2.0);
// Reset to default
window.SubwayBuilderAPI.actions.setSpeedMultiplier('fast', 1.0);Bonds#
issueBond#
Issue a new bond to raise capital. Returns { success: boolean, message?: string }.
const result = window.SubwayBuilderAPI.actions.issueBond('SMALL');
if (result.success) {
console.log('Bond issued!');
} else {
console.log('Failed:', result.message);
}payBond#
Pay down an existing bond. Returns { success: boolean, message?: string }.
const result = window.SubwayBuilderAPI.actions.payBond('bond-id', 50_000_000);getBonds#
Get all current bonds. Returns Bond[].
const bonds = window.SubwayBuilderAPI.actions.getBonds();Game Constants#
modifyConstants#
Modify game rules and constants at runtime. This is a top-level API method, not under actions.
window.SubwayBuilderAPI.modifyConstants({
STARTING_MONEY: 10_000_000_000, // 10B instead of 3B
DEFAULT_TICKET_COST: 5,
CONSTRUCTION_COSTS: {
TUNNEL: {
SINGLE_MULTIPLIER: 0.5 // Half the normal cost
}
}
});Action Summary#
| Action | Parameters | Returns | Description | |||
|---|---|---|---|---|---|---|
setMoney | amount: number | void | Set exact money amount (triggers onMoneyChanged) | |||
addMoney | amount: number | void | Add money (revenue) | |||
subtractMoney | amount: number | void | Subtract money (expense) | |||
setPause | paused: boolean | void | Pause or resume game | |||
setSpeed | `speed: 'slow' \ | 'normal' \ | 'fast' \ | 'ultrafast'` | void | Set game speed |
setTicketPrice | price: number | void | Set ticket price | |||
getTicketPrice | none | number | Get current ticket price | |||
setSpeedMultiplier | `speed: 'slow' \ | 'normal' \ | 'fast' \ | 'ultrafast', multiplier: number` | void | Modify tick rate (non-compounding) |
issueBond | bondTypeId: string | { success, message? } | Issue a new bond | |||
payBond | bondId: string, amount: number | { success, message? } | Pay down a bond | |||
getBonds | none | Bond[] | Get all current bonds | |||
modifyConstants\* | constants: object | void | Modify game rules |
\* modifyConstants is a top-level method on window.SubwayBuilderAPI, not under .actions.
Example: Day/Night Economy Mod#
(function () {
const api = window.SubwayBuilderAPI;
// Track daily expenses
let dailyExpenses = 0;
api.hooks.onMoneyChanged((balance, change, type, category) => {
if (type === 'expense') {
dailyExpenses += Math.abs(change);
}
});
api.hooks.onDayChange((day) => {
// End of day report
if (dailyExpenses > 1_000_000) {
api.ui.showNotification(`High spending day! $${dailyExpenses.toLocaleString()}`, 'warning');
}
// Reset for next day
dailyExpenses = 0;
// Weekly bonus
if (day % 7 === 0) {
api.actions.addMoney(100_000);
api.ui.showNotification('Weekly bonus: $100,000!', 'success');
}
});
})();