The minitrain

The minitrain is the small train the player can drive. It has a fuel tank and a power switch. Text in brackets at the end of a note is extra detail for experienced modders, and you can skip it on a first read.

Trains the minitrain the player uses

Use Minitrain to read the minitrain the player uses.

public static class Trains
{
    public static MinitrainInfo Minitrain { get; }
}
Property Type What it means
Minitrain MinitrainInfo The minitrain the player uses, or the first one found. null when there is none.

MinitrainInfo a snapshot of the minitrain

Trains.Minitrain gives you one of these, or null when there is no minitrain in the loaded scene. It is the minitrain the player is using if there is one, otherwise the first one found. (It reads the game’s Minitrain.)

public sealed class MinitrainInfo
{
    public float Fuel { get; }
    public float Capacity { get; }
    public bool Running { get; }
    public float Speed { get; }
}
Property Type What it means
Fuel float How much fuel is in the tank now.
Capacity float How much fuel the tank holds when full.
Running bool true when the minitrain’s power switch is on.
Speed float How fast the minitrain is going.

Things to know

  • Trains.Minitrain is the minitrain the player is using, or the first one in the scene when the player is not using one. It is null when the scene has no minitrain. To ask whether the player is driving, use Travel.UsingMinitrain. (It is Minitrain.playerUsing, which the game sets in ChangePlayerUsingState and restores when a save loads. The framework searches the active objects of the active scene.)
  • Fuel and Capacity are 0 when the minitrain has no fuel tank. (They are fuelTank.currentFuelAmount and fuelTank.maxFuelAmount.)
  • Running turns itself off when the tank runs dry. The game does that, not the framework. (It is Minitrain.isOn.)
  • Speed is the speed of the train on the track that the minitrain drives. (It is GetTrain().currentSpeed.)

Limits

  • You can’t add fuel. The fuel tank has no call that adds a given amount. Its only filling call takes the fuel out of the player’s inventory, which is the game’s own refuelling action and not a plain “add fuel”. (That call is FillTankFromInventory.)