Resources
PM.Resources defines and edits resources: the fuels, propellants, and other consumables parts store and burn. It also handles recipes, which are resources made by combining other resources. This is one of the smaller, flatter typed modules.
Patching a resource
PM.Resources:Patch(name) patches a resource, targeted by resource name. A resource is a flat record, so most edits are direct field assignments:
PM.Resources:Patch("CheaperMonoprop")
:Named("MonoPropellant")
:Do(function(resource)
resource.costPerUnit = 0.8
end)The fields that come up most: massPerUnit, volumePerUnit, costPerUnit, flowMode (see the enums reference), and the display keys. The full list is in pm-resources.d.lua.
Creating a resource
PM.Resources:NewResource(name, callback) creates a new plain resource. The callback fills it in:
PM.Resources:NewResource("Coolant", function(resource)
resource.displayNameKey = "Resources/Coolant/Name"
resource.abbreviationKey = "Resources/Coolant/Abbr"
resource.massPerUnit = 0.005
resource.volumePerUnit = 5.0
resource.costPerUnit = 1.2
resource.flowMode = "ALL_VESSEL"
end)A new resource only becomes useful once something stores it (a resource container on a part) or produces it (a recipe, below).
Creating a recipe
A recipe is a resource produced from other resources. PM.Resources:NewRecipe(name, callback) creates one, and inside the callback its ingredients list takes entries with :Add(name, unitsPerRecipeUnit):
PM.Resources:NewRecipe("Methalox", function(recipe)
recipe.displayNameKey = "Resources/Methalox/Name"
recipe.ingredients:Add("Methane", 0.5)
recipe.ingredients:Add("Oxidizer", 0.5)
end)Each :Add says how many units of that ingredient go into one unit of recipe output. The ingredients list is keyed by ingredient name, so you can also patch an existing recipe's ingredients the same way you would any indexed list.
Resource units for the UI
PM.Resources:RegisterUnits(value) registers a resource-units definition, which the UI uses to display amounts. Pass it the JSON value describing the units. Use this when a new resource needs custom unit display.
What goes where
Changing an existing resource's numbers:
Patch.A brand new simple consumable:
NewResource.A resource that is mixed from others:
NewRecipewithingredients:Add.Custom unit display for a resource:
RegisterUnits.