Text operations let you change a text field based on its current value, instead of just setting the new value. For example, you can append or prepend text without removing the current text.
They're set using the TextOperations field for an EditData or
EditMap patch.
Before we delve into the specifics, here's a quick example of how text operations work.
First, here's how you'd add an NPC gift taste without text operations:
{
"Action": "EditData",
"Target": "Data/NPCGiftTastes",
"Entries": {
"Universal_Love": "74 446 797 373 279 127 128" // replaces current value
}
}This is pretty simple, but unfortunately it overwrites any previous values. That will remove any
changes from other mods or in future game updates. So instead, we can use the Append
operation to add new gift tastes without changing the other values:
{
"Action": "EditData",
"Target": "Data/NPCGiftTastes",
"TextOperations": [
{
"Operation": "Append",
"Target": ["Entries", "Universal_Love"],
"Value": "127 128",
"Delimiter": " " // if the field isn't empty, add a space between the old & new text
}
]
}See the next section for more info on each operation type and their expected fields.
All text operations have these basic fields:
| field | purpose |
|---|---|
Operation |
The text operation to perform. See the sections below for a description of each operation. |
Target |
The specific text field to change, specified as a breadcrumb path.
Each path value represents a field to navigate into. The possible path values depend on the patch
type; see the This field supports tokens and capitalisation doesn't matter. |
The Append operation adds text at the end of the current field, with an optional delimiter
between the old and new text.
This expects these fields:
| field | purpose | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
See common fields above. |
|||||||||||||||
Value |
The text to append. Like most Content Patcher fields, whitespace is trimmed from the start and
end; use the This field supports tokens and capitalisation doesn't matter. |
||||||||||||||
Delimiter |
(Optional) The characters to add between the current and new text. If you don't specify the
delimiter, it'll default to For example, let's say the field contains
If the field is empty, the delimiter is ignored:
|
For example, this adds two item IDs to the list of universally loved gifts:
{
"Action": "EditData",
"Target": "Data/NPCGiftTastes",
"TextOperations": [
{
"Operation": "Append",
"Target": ["Entries", "Universal_Love"],
"Value": "127 128",
"Delimiter": " "
}
]
}The Prepend operation adds text at the start of the current field, with an optional delimiter
between the old and new text.
This is exactly identical to the Append operation otherwise.
The RemoveDelimited operation parses the target text into a set of values based on a delimiter,
then removes one or more values which match the given search text.
This expects these fields:
| field | purpose | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
See common fields above. |
|||||||||||||
Search |
The value to remove from the text. This must match the entire delimited value to remove, it won't remove substrings within each delimited value. This field supports tokens, and capitalization does matter. |
||||||||||||
Delimiter |
The characters which separate values within the target text. For example, let's say the target text contains
|
||||||||||||
ReplaceMode |
(Optional) Which delimited values should be removed. The possible options are:
Defaults to |
For example, this removes prismatic shard (item 74) from the list of universally loved gifts:
{
"Action": "EditData",
"Target": "Data/NPCGiftTastes",
"TextOperations": [
{
"Operation": "RemoveDelimited",
"Target": ["Entries", "Universal_Love"],
"Search": "74",
"Delimiter": " "
}
]
}- Author guide for other actions and options