# Stages

A mission is a sequence of stages. Each stage has an objective, the actions it runs, the branches that decide where it goes next, and optionally a reward. This page covers reaching, editing, and creating stages.

## The stage list

A mission's stages are on `mission.missionStages`, an indexed list keyed by stage name. You reach a stage by name and edit it, the same way as any [indexed list](/doc/typed-modules-nMMO0SZ6ac):

```lua
PM.Missions:Patch("RetuneStageObjective")
           :Named("KSP2Mission_Main_Mun_01")
           :Do(function(mission)
               mission.missionStages:Patch("Land", function(stage)
                   stage.Objective = "Land softly on the Mun"
                   stage.DisplayObjective = true
               end)
           end)
```

You can also iterate the stages with `pairs` when you want to touch all of them.

## What is on a stage

The fields you most often set:

* `Objective` and `DisplayObjective` control the objective text shown to the player.
* `actions` is the list of [actions](/doc/actions-6KiGnOYRI7) the stage runs.
* `branches` is the list of branches, each pairing a [condition](/doc/conditions-fmWJskmwWx) with the stage it transitions to.
* `MissionReward`, `MissionRewardType`, and `RewardAmount` configure the payout. See below.

## Creating a stage

`PM.Missions:CreateStage(name, callback)` builds a new stage and runs your callback to configure it. You then add it to a mission's stage list. Building a complete, working stage means filling in its objective, actions, and branches, so this is more involved than editing one. Copying the form of a stage from an existing mission is the reliable starting point, and the [patch cache](/doc/caching-and-invalidation-QifFi4oev9) holds those missions' final JSON to copy from.

## Rewards

A stage's reward is on `stage.MissionReward`, whose definitions are an indexed list keyed by reward type (`MissionRewardType`). The simple science-point payout is also expressible through the stage's `MissionRewardType` and `RewardAmount` fields directly. For anything richer, edit the `MissionReward` definitions list.

```lua
mission.missionStages:Patch("Complete", function(stage)
    stage.MissionRewardType = "SciencePoints"
    stage.RewardAmount = "50" -- RewardAmount is a string field, so the number is quoted
end)
```