Line 6,967: |
Line 6,967: |
| | | |
| ===Tokenizable string format=== | | ===Tokenizable string format=== |
− | Stardew Valley 1.6 adds support for literal strings that contain tokens. These are only usable in specific fields (their docs will say 'tokenizable string' with a link to this section). | + | Stardew Valley 1.6 adds ''tokenizable strings'', which support any combination of literal text and token values. That includes a set of built-in tokens like <samp>FarmName</samp>, <samp>LocalizedText</samp>, etc. |
| | | |
− | ====Literal text====
| + | For example, previously you often needed to load text from a [[Modding:Modder Guide/Game Fundamentals#String keys|translation string key]]. With this new format, you can use the literal text directly in the asset instead (including [[Modding:Content Patcher|Content Patcher]] tokens): |
− | Previously you often needed to load text from a [[Modding:Modder Guide/Game Fundamentals#String keys|string key]] in data assets. With this new format, you can use the literal text directly in the asset instead (including Content Patcher tokens):
| |
| | | |
| <syntaxhighlight lang="js"> | | <syntaxhighlight lang="js"> |
Line 6,976: |
Line 6,975: |
| "Dialogue": "Strings\\StringsFromCSFiles:ShopMenu.cs.11488", | | "Dialogue": "Strings\\StringsFromCSFiles:ShopMenu.cs.11488", |
| | | |
− | // after: literal text supported | + | // after: any combination of literal text and tokens |
− | "Dialogue": "Welcome to Pierre's!",
| + | "Dialogue": "Welcome to Pierre's, {{PlayerName}}! How is [FarmName] doing?", |
− | | |
− | // after: literal text with Content Patcher tokens
| |
− | "Dialogue": "Welcome to Pierre's, {{PlayerName}}! {{i18n: translatable-text}}", | |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
− | ====Tokens====
| + | Tokenizable strings are only usable in specific fields (as indicated in their wiki or code docs). |
− | You can inject tokens using square brackets. For example, <code>"[LocalizedText Strings\StringsFromCSFiles:ShopMenu.cs.11488] This is raw text"</code> will show something like "''Welcome to Pierre's! This is raw text''". Token names are not case-sensitive.
| |
− | | |
− | Here are the supported tokens:
| |
− | {| class="wikitable"
| |
− | |-
| |
− | ! token format
| |
− | ! output
| |
− | |-
| |
− | | <samp>[ArticleFor {{t|word}}]</samp>
| |
− | | The grammatical article (''a'' or ''an'') for the given word when playing in English, else blank. For example, <code>[ArticleFor apple] apple</code> will output ''an apple''.
| |
− | |-
| |
− | | <samp>[CharacterName {{t|name}}]</samp>
| |
− | | The translated display name for an NPC, given their internal name.
| |
− | |-
| |
− | | <samp>[DayOfMonth]</samp>
| |
− | | The numeric day of month, like <samp>5</samp> on spring 5.
| |
− | |-
| |
− | | <samp>[EscapedText]</samp><br /><samp>[EscapedText {{t|text}}]</samp>
| |
− | | Marks a snippet of text as a single argument, so it can be safely passed into another token's space-delimited arguments even if it's empty or contains spaces.
| |
− | | |
− | For example, the <samp>SpouseFarmerText</samp> expects two arguments separated by spaces. This passes an empty string for the first one, and text containing spaces for the second:
| |
− | <pre>[SpouseFarmerText [EscapedText] [EscapedText spouse 28 63 2]]</pre>
| |
− | |-
| |
− | | <samp>[FarmerUniqueID]</samp>
| |
− | | The target player's unique internal multiplayer ID
| |
− | |-
| |
− | | <samp>[FarmName]</samp>
| |
− | | The farm name for the current save (without the injected "Farm" text).
| |
− | |-
| |
− | | <samp>[FarmerStat {{t|key}}]</samp>
| |
− | | The value of a [[#Stat changes for C# mods|tracked stat]] for the current player. See the [[#Game state queries|<samp>PLAYER_STAT</samp> game state query]] for a list of useful stats.
| |
− | | |
− | For example:
| |
− | <syntaxhighlight lang="js">"You've walked [FarmerStat stepsTaken] so far."</syntaxhighlight>
| |
− | |-
| |
− | | <samp>[GenderedText {{t|male text}} {{t|female text}}</samp>
| |
− | | Depending on the target player's gender, show either the male text or female text. If the text contains spaces, you'll need to escape them using <samp>EscapedText</samp>.
| |
− | |-
| |
− | | <samp>[LocalizedText {{t|string key}}]</samp><br /><samp>[LocalizedText {{t|string key}} {{t|token values}}+]</samp>
| |
− | | Translation text loaded from the given [[Modding:Modder Guide/Game Fundamentals#String keys|string key]]. If the translation has placeholder tokens like <samp>{0}</samp>, you can add the values after the string key.
| |
− | |-
| |
− | | <samp>[LocationName {{t|location ID}}]</samp>
| |
− | | The translated display name for a location given its ID [[#Custom locations|in <samp>Data/Locations</samp>]].
| |
− | |-
| |
− | | <samp>[PositiveAdjective]</samp>
| |
− | | A random adjective from the <samp>Strings\Lexicon</samp> data asset's <samp>RandomPositiveAdjective_PlaceOrEvent</samp> entry.
| |
− | |-
| |
− | | <samp>[Season]</samp>
| |
− | | The current season name, like ''spring''.
| |
− | |-
| |
− | | <samp>[SpouseFarmerText {{t|spouse is farmer text}} {{t|spouse is NPC text}}</samp>
| |
− | | Show a different text depending on whether the target player's spouse is a player or NPC. If the text contains spaces, you'll need to escape them using <samp>EscapedText</samp>.
| |
− | |-
| |
− | | <samp>[SpouseGenderedText {{t|male text}} {{t|female text}}]</samp>
| |
− | | Equivalent to <samp>GenderedText</samp>, but based on the gender of the player's NPC or player spouse instead.
| |
− | |-
| |
− | | <samp>[SuggestedItem {{o|interval}} {{o|sync key}}]</samp>
| |
− | | '''(For shops only.)''' The name of a random item currently available in the shop stock.
| |
− | | |
− | The result will be identical for all queries with the same {{o|sync key}} during the given {{o|interval}} (one of <samp>tick</samp>, <samp>day</samp>, <samp>season</samp>, <samp>year</samp>), including between players in multiplayer mode. If omitted, they default to <samp>day</samp> and the shop ID respectively.
| |
− | |}
| |
− | | |
− | When passing an input argument for tokens like <samp>ArticleFor</samp>, the input can contain its own nested tokens. For example, <code>"[ArticleFor [SuggestedItem]] [SuggestedItem]"</code> would output something like ''an Apple''.
| |
− | | |
− | If you're using [[Modding:Content Patcher|Content Patcher]], you can use its tokens anywhere in the string (including within square brackets); they'll be expanded before the game parses the string. For example, <code><nowiki>"{{Spouse}} would love [ArticleFor [SuggestedItem]] [SuggestedItem]!"</nowiki></code> would output something like "''Alexa would love an Apple!''".
| |
| | | |
− | ====Extensibility====
| + | See [[Modding:Tokenizable strings]] for usage. |
− | C# mods can define custom tokens by calling <code>TokenParser.RegisterParser("tokenName", ...)</code>. To avoid conflicts, prefixing custom condition names with your mod ID (like <samp>Example.ModId_TokenName</samp>) is strongly recommended.
| |
| | | |
| ===[[Modding:Event data|Event]] changes=== | | ===[[Modding:Event data|Event]] changes=== |