# Text assets

Text-asset patches change JSON-backed game content while it is loaded. They can edit existing definitions or add new content without replacing the complete source asset.

Common targets include parts, resources, planets, science definitions, missions, tech nodes, variants, and audio definitions.

## Getting started

Start with [Getting Started](/doc/getting-started-M6lopbmYlB) for the patch-file layout, editor support, and a first working patch.

[Core Concepts](/doc/core-concepts-JzW14TdnTL) explains the patch lifecycle, asset targeting, callbacks, features, dependencies, ordering, JSON values, configuration, and `pm_summary.log`.

## APIs and typed modules

* [Generic JSON API](/doc/generic-json-api-fqEwMuvrGb) patches any supported JSON-backed asset directly.
* [Typed Modules](/doc/typed-modules-nMMO0SZ6ac) provide helpers for parts, missions, planets, resources, science, V-SwiFT variants, and audio.
* [Advanced Topics](/doc/advanced-topics-uybkyjgPpJ) covers shared Lua modules, cross-mod compatibility, C# extensions, converters, and caching.
* [Reference](/doc/reference-57SBVho6Kg) contains the LuaPatch cheat sheet, enum values, and glossary.

## Script globals

Patch scripts receive several useful globals:

* `PM` registers patches through APIs such as `PM.Parts:Patch(...)`, `PM.Planets:Patch(...)`, and `PM.JSON:Patch(...)`.
* `J` creates JSON values that cannot be represented directly by ordinary Lua tables.
* `ModId` identifies the current mod.
* `Location` provides the patch location.
* `Config` reads the mod's configuration.
* `CampaignConfig` reads the settings that each campaign keeps.
* `Features` reads the active [feature set](/doc/campaign-features-9YIewcIArR).
* `Enabled` tells whether the mod is on in the active feature set.
* `Log` writes diagnostic messages.

Use `Features` and `Enabled` only in runtime code. To gate patches, use [`:Feature`](/doc/features-geboWdIiDN).

See [Working with JSON](/doc/working-with-json-fWfY8KrejF), [File layout and discovery](/doc/file-layout-and-discovery-vYcsLN5rtw), and [Config integration](/doc/config-integration-aTM54Tfqkz) for details.

## Minimal example

This patch finds the part named `eva_kerbal` and changes its crash tolerance:

```lua
PM.Parts:Patch("KerbalImpactToleranceFix")
    :Named("eva_kerbal")
    :Do(function(part)
        part.crashTolerance = 30.0
    end)
```

`:Patch` gives the patch a stable name, `:Named` selects the target, and `:Do` applies the change.

---

**Documents**

- [Getting Started](https://docs.ksp2redux.org/s/0a4a3e31-0b40-48e0-bd81-e14856f80d3d/doc/getting-started-M6lopbmYlB)
- [Core Concepts](https://docs.ksp2redux.org/s/0a4a3e31-0b40-48e0-bd81-e14856f80d3d/doc/core-concepts-JzW14TdnTL)
- [Generic JSON API](https://docs.ksp2redux.org/s/0a4a3e31-0b40-48e0-bd81-e14856f80d3d/doc/generic-json-api-fqEwMuvrGb)
- [Typed Modules](https://docs.ksp2redux.org/s/0a4a3e31-0b40-48e0-bd81-e14856f80d3d/doc/typed-modules-nMMO0SZ6ac)
- [Advanced Topics](https://docs.ksp2redux.org/s/0a4a3e31-0b40-48e0-bd81-e14856f80d3d/doc/advanced-topics-uybkyjgPpJ)
- [Reference](https://docs.ksp2redux.org/s/0a4a3e31-0b40-48e0-bd81-e14856f80d3d/doc/reference-57SBVho6Kg)