---
title: MD saves and migrations
summary: First startup, saved variables, settings updates and migration in a single player mod.
section: scripting
kind: guide
status: example
tags: ["X4","modding","md","persistence"]
sources: ["https://wiki.egosoft.com/X4%20Foundations%20Wiki/Modding%20Support/"]
---
## Cue lifecycle
MD state belongs to the saved game. A completed cue need not execute again after loading, so code added only to an old Init may not initialize new fields in an existing save. Separate first startup from migration to a new data version.
## A new field
The example belongs in the context that owns your settings. It initializes a missing schema version, creates a missing settings table and advances the version. It does not install a load handler; call it from your actual initialization/migration path and use the correct variable namespace.
```xml
```
## Preserve the player's choices
Write defaults only for missing fields. Do not reset settings, created objects or mission progress on each load. Check object existence before using stored references. Temporary UI handles and caches are not persistent game state.
## Verify a mod update
Create a save with the previous data version, load it with the new extension, verify that old values survive and new fields appear, save and completely restart X4, then read back the result again. Initialization must not create a second object. For ship property changes, test a new and an existing ship separately: parameter application and damage state can have different lifecycles.