Your first patch
On this page you will find an example first patch that changes the crash tolerance for kerbals, and explains every single part of it. This is to be used as a reference for the general form Lua patches take in patch manager.
The whole thing
PM.Parts:Patch("KerbalImpactToleranceFix")
:Named("eva_kerbal")
:Do(function(part)
part.crashTolerance = 30.0
end)Put that in a .lua file inside your mod (see file layout and discovery). Launch the game. The EVA Kerbal now tolerates a 30 m/s impact in each campaign that has your mod on.
A newly installed mod is on at the main menu. It is not on in campaigns until you turn it on. Before you start a test campaign, do one of these:
Open the mods menu, select your mod, and mark it under Default Features.
Press Edit Pack on the new campaign menu, and turn your mod on there.
When you next load an existing save, the save offers to add your mod. See Campaign features.
Reading it piece by piece
**PM.Parts:Patch("KerbalImpactToleranceFix")** registers a new patch on the parts module. The string is the patch's name. It is for you and for other patches that might want to order around yours, so make it descriptive and unique within your mod. It is not the name of the part you are changing.
The call returns a patch object, and every following line is a method on it. They chain because each one returns the patch again. You can write the chain on one line or spread it out. Spreading it out reads better once there are more than two or three calls. This patch uses just two methods, :Named and :Do. There are more (for ordering, dependencies, and conditions), but a basic edit does not need them, and they come later.
**:Named("eva_kerbal")** decides which assets the patch touches. Without it, the patch would run against every part in the game. With it, the patch only runs against the part whose id is eva_kerbal. You can pass several names, or call :Named more than once. See targeting assets.
**:Do(function(part) ... end)** is the change. PatchManager calls your function once per matched asset, handing you that asset. You mutate it in place. Here part is the EVA Kerbal's definition, and setting part.crashTolerance changes it. You do not return anything and you do not need to save. Whatever you set on part is what the game loads. See the Do callback.
A version that reaches deeper
Top-level fields like crashTolerance are direct assignments. Many values live one or two levels down, inside a module. The helpers for that are covered in the Parts module, but here is the form so the nesting is not a surprise:
PM.Parts:Patch("InflatableHeatShieldHeatTolerance")
:Named("heatshield_2v_inflatable")
:Do(function(part)
part.maxTemp = 3000.0
part.Module_Deployable.Data_Deployable.deployMaxTemp = 3500.0
end)The first line is a top-level field. The second reaches into the part's deployable module and the data inside it. Same idea, just deeper into the tree.
Next
You have written a patch. Now learn where it goes so the game actually finds it.