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.

Money Actions#

setMoney#

Set the player's money to an exact amount.

javascript
window.SubwayBuilderAPI.actions.setMoney(10_000_000);

addMoney#

Add money (income/bonus). Optionally specify a category.

javascript
// Add $1,000,000 as a bonus
window.SubwayBuilderAPI.actions.addMoney(1_000_000, 'bonus');

// Add without category
window.SubwayBuilderAPI.actions.addMoney(500_000);

subtractMoney#

Subtract money (expense/penalty). Optionally specify a category.

javascript
// Subtract $500,000 as maintenance
window.SubwayBuilderAPI.actions.subtractMoney(500_000, 'maintenance');

Game Flow Actions#

setPause#

Pause or resume the game.

javascript
// Pause the game
window.SubwayBuilderAPI.actions.setPause(true);

// Resume the game
window.SubwayBuilderAPI.actions.setPause(false);

setSpeed#

Set the game speed.

javascript
// Available speeds: 'slow', 'normal', 'fast', 'ultrafast'
window.SubwayBuilderAPI.actions.setSpeed('fast');
window.SubwayBuilderAPI.actions.setSpeed('ultrafast');

Game Constants#

modifyConstants#

Modify game rules and constants at runtime.

javascript
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#

ActionParametersDescription
setMoneyamount: numberSet exact money amount
addMoneyamount: number, category?: stringAdd money
subtractMoneyamount: number, category?: stringSubtract money
setPausepaused: booleanPause or resume game
setSpeedspeed: stringSet game speed
modifyConstantsconstants: objectModify game rules

Example: Day/Night Economy Mod#

javascript
(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) {
            const bonus = 100_000;
            api.actions.addMoney(bonus, 'weekly-bonus');
            api.ui.showNotification(`Weekly bonus: $${bonus.toLocaleString()}!`, 'success');
        }
    });
})();