Skip to content

Language Reference

Kakrain edited this page Jun 14, 2026 · 2 revisions

Language Reference

This page explains the full scripting language used by KenshiPatcher .patch files.

It is designed for mod creators, not typical users.


Overview

Patch rules are written using three primary statement types:

Statement Type Symbol Purpose
Definition := Select records into a variable
Extraction <<< Split records into matching and remaining
Procedure -> / ~> Modify records

Additional syntax elements:

Feature Symbol
Lambda expressions =>
Global Functions @ prefix
Comments ;

Comments

; This is a comment

Everything after ; on the same line is ignored.


Variables & Selectors (:=)

Definitions select records from mods into variables.

variable := (mod_selector)(mode:TYPE | condition)

Mod Selector

Selector Meaning
(all) Search in all loaded mods
(mod1.mod) Search only in mod1.mod
(mod1.mod,mod2.mod) Search only in these mods
(*mod1.mod,mod2.mod) Search in all mods except these

.mod extension is required.


Mode

Mode Meaning
A Select all matching records
E Select first matching record
Number Select N records

Record Types

You must specify a valid Kenshi record type:
(e.g. RACE, ARMOUR, BUILDING, BIOME, etc)

Use FCS or KenshiUtilities to find the correct type name.


Condition Expressions

Conditions filter which records are selected.

Logical operators supported:

Operator Meaning
! NOT
&& AND
|| OR
== Equals
!= Not equals
< Less than
> Greater than
<= Less or equal than
>= Greater or equal than

Arithmetic Operations

Operator Meaning
+ plus
- minus
* multiplication
/ division
% modulo

Extraction (<<<)

Split records: left gets matching, right keeps remaining.

hairyraces <<< (allraces|hasAnyAsExtraData(hairs,"hair"))

After this:

  • hairyraces now contains only matching elements
  • allraces loses those entries permanently

Use when you want exclusive subsets.


Lambda Expressions (=>)

A->SetText(x=>x + " you know? ")

Here, it modifies every text (text0, text1, text2,...etc) to append " you know? " at the end to every text

Functions

Additionally there are multiple kind of functions:

Clone this wiki locally