Modding:Dialogue

From Stardew Valley Wiki
Revision as of 00:10, 16 February 2019 by Pathoschild (talk | contribs) (→‎Generic dialogue: expand and clarify intro)
Jump to navigation Jump to search

Index

This page explains how the game stores dialogue text, its format, and how the game parses it. This is an advanced guide for mod developers.

Data

The dialogue text is stored in four sets of files.

Character-specific dialogue

Characters\Dialogue\*.xnb contains most of the dialogue for each character (one file per character). The game will choose dialogue from one of the sections below, in the order shown here.

Special dialogue

There are a few predefined keys for specific cases:

key format description
danceRejection Dialogue used to reject an offer to dance at the Flower Dance. (A different dialogue is used if they've already agreed to dance with another player.)
divorced Dialogue shown when you speak to your divorced spouse.
<location>_Entry Possible dialogue lines shown above the NPC's name when they enter the named <location>, with a 50% chance. This dialogue entry can contain multiple options separated by /; the game will randomly choose one to display.
Example: SeedShop_Entry: "Hi, Pierre!/Now, what do I need.../Ah, that looks good!/Makin' my special sauce tonight!/Pierre! What's fresh?/Pierre! Waddya got for me?"
ComeBackLater
Snoring
Gil's dialogue when you haven't completed any new Adventure Quest goals. ComeBackLater will be shown once, and all subsequent dialogues will show Snoring.

Location dialogue

Otherwise the game will choose dialogue in this order.

Variants:

  • Each key can optionally be prefixed with a season name, like springMountain_47_23.

The game will check variants in this order: <season><key>, and <key>. The variants aren't listed below for simplicity.

key format description
<location>_<x>_<y> Dialogue shown in the named location when the NPC is standing at tile position <x>, <y>.
Example: Mountain_47_23: "I come here for the peace and quiet."
<location>_<dayName> Dialogue shown in the named location on the given day of week.
Example: winter_Fri: "One thing I've learned living here... everyone stares at you if you look different."
<location><hearts> Dialogue shown in the named location if you have at least <hearts> hearts with them. The <hearts> will be checked in the order 10, 8, 6, 4, 2 (no other value will be recognised).
Example: Saloon8: "Hi there @. I'm glad to see you! You're always welcome here."
<location> Dialogue shown in the named location.
Example: Saloon: "Now that I'm here I can finally relax and socialize a bit."

Rain dialogue

Characters\Dialogue\rainy.xnb contains one dialogue entry per NPC. There's a roughly 50% chance they'll use this dialogue if one of the above didn't match, it's raining, and you're not married to or divorced from them.

Generic dialogue

Otherwise the game will choose a dialogue using one of these key formats (in precedence order):

  1. <season>_<key>_inlaw_<spouseName>
  2. <season>_<key>
  3. <key>_inlaw_<spouseName>
  4. <key>

For each variation above: <season> is a season name (like spring14); _inlaw_<spouseName> matches if the player is married to the named NPC, regardless of whether the speaking NPC is related to the named one (like Sat_inlaw_Abigail); and <key> is one of the formats listed below.

key format description
<dayOfMonth> Dialogue shown on the given day of month in the first year only.
Example: 10: "Did you watch the game last night?#$b#Or wait, do you even have a TV set...?"
<dayOfMonth>_<firstOrLaterYear> Dialogue shown on the given day of month in the first/later year.
Example: 2_1: "My husband Kent is a soldier, working overseas. That's why he's not here right now.#$b#I know he'll come back safe once his tour is over!!#$e#Need something?"
<dayOfWeek><hearts>_<firstOrLaterYear> Dialogue shown on the given day of week if you have at least <hearts> hearts with them, in the first/later year. The <hearts> will be checked in the order 10, 8, 6, 4, 2 (no other value will be recognised).
Bug: only shown if an equivalent <dayOfWeek><hearts> key also exists.
Example: Thu2_2: "Well, my Dad is back. Have you met him?#$b#I'm just glad he's okay."
<dayOfWeek><hearts> Dialogue shown on the given day of week if you have at least <hearts> hearts with them. The <hearts> will be checked in the order 10, 8, 6, 4, 2 (no other value will be recognised).
Example: Sun4: "Hey, @.#$e#How's your day going?"
<dayOfWeek>_<firstOrLaterYear> Dialogue shown on the given day of week in the first/later year.
Bug: only shown if an equivalent <dayOfWeek> key also exists.
Example: Sat_1: "Dad's coming back soon!#$b#I hope he brings me some toys.$u"
<dayOfWeek> Dialogue shown on the given day of week.
Example: Mon: "Oh, hey. Taking a break from work?"

Fallback

If none of the above match, the game will show the value with key NPC.cs.4061 in Strings\StringsFromCSFiles.xnb. (English version: "Hi.")

Marriage dialogue

Characters\Dialogue\MarriageDialogue.xnb contains dialogue text for all spouses, and each NPC may optionally have their own dialogue file like Characters\Dialogue\MarriageDialogueAbigail.xnb. When looking up a dialogue key, it will use the one in the NPC's file if it exists, else the one in the generic file, else a default text (usually blank).

Each dialogue entry has a key with one of these formats:

key format description
<season>_<day> Dialogue shown when the day starts, if <season> and <day> match the current date.
Example: fall_1: "The scent is unmistakable... mushroom, rotting leaves, pumpkin. It's fall, alright. Isn't it lovely?"
patio_<spouse> Dialogue shown when the NPC is standing on the patio.
<weather>_<dayOrNight>_<random> Daily dialogue. <weather> is Rainy if it's raining, else Indoor (even if they're not indoors). <dayOrNight> is Night after 6pm, else Day. <random> is a number -1 to 4, used to randomly select an entry.
Example: Rainy_Night_3: "On nights like this, I like to turn the light down low and just listen...$8"
funLeave_<spouse> TODO
jobLeave_<spouse> TODO
funReturn_<spouse> Dialogue shown after 1pm when they enter the farmhouse but before reaching their target position, but only on Monday (any NPC) or Friday (if not Maru/Penny/Harvey).
Example: funReturn_Abigail: "Hey! Did you have a good day? Mine went well. It was refreshing to take a walk.$h"
jobReturn_<spouse> Dialogue shown after 1pm when they enter the farmhouse but before reaching their target position, but only if funReturn isn't shown instead.
Example: jobReturn_Penny: "#$c .5#Good evening. My day was fine, thanks! How was yours?$h#$e#Jas and Vincent weren't behaving very well today. I'm still all wound up..."
<season>_<spouse> Dialogue shown at 9+ heart levels with a 5% chance each day.
Example: fall_Abigail: "Do I smell pumpkin on you? Maybe I'm just dreaming...$h"
Outdoor_<spouse> Dialogue shown on the farm with a 20% chance.
Example: Outdoor_Abigail: "I'm just going to hang out here, okay?#$e#There's a lot of interesting bugs and things out here. *chuckle*$h"
Outdoor_<random> Dialogue shown on the farm with an 80% chance. <random> is a number 0–4, used to randomly select an entry.
Example: Outdoor_3: "It's pretty cool that we have a cave on our property. It's something I always dreamed about.$h"
spouseRoom_<spouse> Dialogue shown when the NPC is in their room.
Example: spouseRoom_Abigail: "$c .5#I got up a little before you and fed David Jr. He's very active this morning.#$e#I hope you don't mind the guinea pig smell."
OneKid_<random> Dialogue shown when standing in the kitchen, if they have one child. <random> is a number 0–4, used to randomly select an entry.
OneKid_1: "I wonder if %kid1 will grow up to be a farmer like you?"
TwoKids_<random> Dialogue shown when standing in the kitchen, if they have two children. <random> is a number 0–4, used to randomly select an entry.
TwoKids_2: "I had a dream that %kid2 will grow up to be a famous monster hunter. I've already been thinking about a little armor set."
<affection>_<random> Dialogue shown inside the farmhouse between 11am and 6pm, or when the day starts if a different dialogue isn't selected. <affection> is randomly Bad or Neutral if they have less than 9 hearts; 50% chance of Good and 75% chance of Good if you have 10+ or 11+ hearts respectively; else Neutral <random> is a number 0–9, used to randomly select an entry.
Example: Good_5: "I was just admiring the mermaid's pendant you gave me... I'll proudly wear this to my grave.$l"

Event files

Data\Events\*.xnb contains event scripts, including any dialogue in the event (see Modding:Event data).

Animation descriptions

Data\animationDescriptions.xnb contains short bits of dialogue to go with certain schedule points.

Strings from CS files

Strings\StringsFromCSFiles.xnb contains miscellaneous translations. That includes NPC dialogue defined in the code, dialogue that's shared between multiple characters, dialogue for some hardcoded events like marriage, etc.

The file has entries in the form "<key>": "dialogue string", where the key is an arbitrary unique identifier. These must exactly match the key expected by the game, but the keys are just unique identifiers — even though most keys look like <file name>.<line number>, that's just the convention originally used to assign IDs and it has no meaning or effect (nor does it even necessarily match the current file name or line number).

NPC-specific generic dialogue

With some ingenuity, you can make each NPC respond differently instead of using the normal static dialogue. For example, you can use Content Patcher to change NPC.cs.3962 and NPC.cs.3963 (to give a bouquet), and NPC.cs.3980 (for the mermaid pendant acceptance):

{
   "Action": "EditData",
   "Target": "Strings/StringsFromCSFiles",
   "Entries": {
      "NPC.cs.3962": "$q 10001 give_flowersA#?!...#$r 10001 0 give_flowersA# [Give Bouquet]",
      "NPC.cs.3963": "$q 10001 give_flowersB#?!...#$r 10001 0 give_flowersB# [Give Bouquet]",
      "NPC.cs.3980": "$q 10001 give_pendant#?!...#$r 10001 0 give_flowersB# Will you marry me?"
   }
}

In this example, each NPC will get their response from the give_flowersA, give_flowersB, and give_pendant dialogue key in their character dialogue files. (See format below for more info on the syntax.) Note that these should be added for all datable characters to avoid errors. For example, you could add this for Haley:

{
   "Action": "EditData",
   "Target": "Characters/Dialogue/Haley",
   "Entries": {
      "give_flowersA": "Oh.. these are beautiful.$1#$b#...What? You want to be my Boyfriend?$8^...What?  You want to be my Girlfriend?$8#$b#....I thought we already were together.$1",
      "give_flowersB": "Ohhh, @!  I would love to be your true love.$1",
      "give_pendant": ".....$8#$b#@, I don't know what to say..$8#$b#...$7#$b#Yes... I accept...$4#$b#I can't wait to tell the Mayor... Everything should take 3 days to set up.$1"
   }
}

This can be used for other generic responses, and you even can avoid the "Give Bouquet" by asking for an answered question's ID.

Algorithm

The game finds dialogue as follows:

  1. Event dialogue is read from the appropriate event commands (see Modding:Event data).
  2. Location-specific dialogue is read from StringsFromCSFiles <location>.cs.
  3. Else character dialogue is read from the character-specific files.
  4. If no dialogues were found, the game resorts to hardcoded dialogue from the StringsFromCSFiles files (specifically keys prefixed with NPC.cs NPC.cs).

Format

Dialogue text can contain tokens and commands which control the dialogue box, change the text (e.g. switch between gender-specific strings), inject values, etc. These are parsed by the Dialogue class.

Special tokens:

character description
# Separates two commands in a dialogue string.
{ TODO. Stands for "breakSpecialCharacter".
^ Gender switch character. The text before it is shown for male farmers, the text after it for female farmers.
Example: Oh, good morning Mr. @!^Oh, good morning Ms. @!
% Turns the dialogue box into a generic text box.
Example: "%Abigail is lost in her music."
* TODO. Stands for "quickResponseDelineator".

Portrait commands

These commands determine which portrait will be shown in the dialogue box. Portrait commands go to the end of a line of dialogue:

"fall_Fri6": "When I was a little girl, my father abandoned us.$s#$b#I'm sorry to make things uncomfortable for you...$u#$e#Anyway... How's the farming life going?",
command description
$neutral Switch the speaking character to their neutral portrait.
$h Switch the speaking character to their happy portrait.
$s Switch the speaking character to their sad portrait.
$u Switch the speaking character to their unique portrait.
$l Switch the speaking character to their love portrait.
$a Switch the speaking character to their angry portrait.
$<id> Switch the speaking character to the portrait at the given index in their portraits file. Portraits are numbered from left to right and top to bottom, starting at $0. All characters have six standard portraits: $0 (neutral), $1 (happy), $2 (sad), $3 (unique), $4 (love), and $5 (angry). Characters may have custom portraits beyond those for their dialogue and cutscenes.
NOTE: $1 can't be used as the first dialogue command (see $1 below).

Dialogue commands

$q <response IDs> <fallback>#<text> Show a dialogue box containing the given question text. If <response IDs> (a list delimited by /) contains an answer already given, the question is skipped (along with the rest of this dialogue line), and instead the dialogue entry identified by <fallback> will be appended to whatever precedes this $q command. The <fallback> dialogue typically uses a $p command to adjust the text based on the player's answer to this question.
$r <response ID> <friendship> <reaction>#<answer text> Define a response option to a $q question dialogue. <answer text> is the text shown. <response ID> is used to group responses for future reference (multiple answers can share an answer ID). <friendship> defines the change in friendship value, positive or negative, if this response is selected. <reaction> names the dialogue entry from the NPC's Content\Characters\Dialogue\*.xnb file that will be the NPC's reaction if this response is selected by the player.
$p <response ID>#<match text>|<no-match text> Stands for "dialoguePrerequisite". Shows different text depending on whether the player gave a particular answer to a previously-asked question. If <response ID> matches an answer the player gave, <match text> is shown; otherwise, <no-match text> is shown. These texts, separated by |, can each contain multiple commands separated by #. This does not need to be the first command in the dialogue string.
$b Indicates pauses in dialogue, where the player will need to click for the next part to load in a new dialogue box.
$e Ends the current dialogue, closing the dialogue box and resuming player control. The dialogue following $e will require a new interaction with the NPC.
$k TODO. Stands for "dialogueKill".
$c <probability>#<text1>#<text2> Show <text1> with a <probability> between 0 and 1; otherwise, show <text2>. E.g. $c 0.9 for a 90% chance of <text1> and a 10% chance of <text2>. NOTE: Replacer commands (see below) do not work in <text1>. This does not need to be the first command in a dialogue string. It is unaffected by daily luck.
$d <bus|joja|cc> dialogueDependingOnWorldState

"Tue4": "$d <dependence>#|Dialogue when dependence value is true.|Dialogue in other situations.",
The dependence can take one of three values: "bus": is the bus fixed?; "joja": is JoJa Mart in business?; "cc": has the Community Centre been completed? This command must start the dialogue string and does not allow for any other dialogue commands in the string.

$y TODO. Stands for "dialogueQuickResponse"; A simpler form of question. Works like $q, but within one and the same text line. It doesn't have neither "dialoguePrerequisite" ($p) nor friendship point changes. It can be triggered indenitelly.
Example: Penny: "$y 'Breakfast?_Yes please._Here you go._No, I'm good_More for me then!'"
$1 <letter ID>#<1st-time text> #$e# <nth-time text> Creates a line of dialogue which the character will only see once (at most). <1st-time text> is shown only if <letter ID> has not been marked as sent yet (and this marks it as sent); otherwise, <nth-time text> is shown. <letter ID> should not correspond to an actual piece of mail (because it will not be sent), but it can be referenced by events or other dialogue lines.
%fork TODO. Seems to have to do with questions and forks, however is used sparingly in game code. May be limited to forking events.
[# # #] Gives the player a random item, from the pool of item IDs within the brackets.

Question example

To understand how $q, $r, and $p work, an example may be helpful. Note how you can format the script to be easier to read:

summer_Fri:
    "I think I'll go to the beach tomorrow!
    #$q 305/306 beachquestion_followup#Would you like to go with me?
        #$r 305 15 beachquestion_yes#Sure, I would love to!
        #$r 306 0 beachquestion_sorry#Oh, sorry, I've already made plans with someone else...
        #$r 306 -10 beachquestion_no#No thank you.
    ",
    beachquestion_yes: "Good! It's a date.$h",
    beachquestion_sorry: "Oh. Darn. Okay.$6",
    beachquestion_no: "Oh. Um. Sorry.$s",
    beachquestion_followup:
        "$p 305
            #Tomorrow should be a lot of fun!$h
            |Hmm, I wonder if I can get someone to go with me...$s
        ",

summer_Sat:
    "The beach is lovely this time of year...
    #$p 305
        #Thanks for coming with me today.$h
        |Oh, hi @, how's it going?
    ",

The dialogue above triggers on any Friday in the summer. The NPC begins with a response that is always shown: "I think I'll go to the beach tomorrow!"

Next they ask you a question.

#$q 305/306 beachquestion_followup#Would you like to go with me?

$q starts the question. 305/306 checks to see if this question has been asked before, and if it has it sends you to the dialogue key beachquestion_followup. (Note that you can name your dialogue keys whatever you like which makes it easier to read.)

Next are the responses the player can give. You can add any number of $r lines; here we have three:

    #$r 305 15 beachquestion_yes#Sure, I would love to!
    #$r 306 0 beachquestion_sorry#Oh, sorry, I've already made plans with someone else...
    #$r 306 -10 beachquestion_no#No thank you.

If you say yes (first option), the game will store ID 305 as the answer given to this question. Next, your friendship with that person increases by 15. beachquestion_yes tells the script which dialogue key continuation to use as a response to your answer.

If you say no (second and third option) the game will store ID 306 as the answer given, then depending on which answer you gave will either not change your friendship with the person, 0, or reduce it, -10. Then it will use either beachquestion_sorry or beachquestion_no to continue the dialogue.

Now we need to make dialogue keys for each response:

    beachquestion_yes: "Good! It's a date.$h",
    beachquestion_sorry: "Oh. Darn. Okay.$6",
    beachquestion_no: "Oh. Um. Sorry.$s",
    beachquestion_followup:
        "$p 305
            #Tomorrow should be a lot of fun!$h
            |Hmm, I wonder if I can get someone to go with me...$s
        ",

Of note here is beachquestion_followup. If the player talks to the NPC again, $q 305/306 will check that the question has already been answered and instead go directly to this key.

$p 305 begins a variable response which means "if the player chose yes, say this line, else say this line instead". If the player answered yes, the NPC responds happily. Otherwise, they will comment that they need to find someone to go with them.

There is another variable response the next day:

summer_Sat:
    "The beach is lovely this time of year...
    #$p 305
        #Thanks for coming with me today.$h
        |Oh, hi @, how's it going?
    ",

Once again the first line (The beach is lovely...) always shows up when the player talks to the NPC, but the next line depends on whether or not they've answered yes the previous day.


Here is another example from Haley's existing dialogue file. Note how the script formatting is harder to read, but the game is able to process both.

    summer_Sat: "Farming sounds so boring...#$q 42/43 summer_Sat_old#What do you even do all day?#$r 42 10 summer_Sat_12#Care for plants#$r 42 10 summer_Sat_12#Explore the caves#$r 43 -10 summer_Sat_13#Snoop around in your room#$r 42 10 summer_Sat_12#Dig for treasure" #!String
    summer_Sat_old: "#$p 43#Hey, you better not be snooping around in my room anymore!$a|But I guess it could get you in pretty good shape." #!String
    summer_Sat_12: "Hmm... sounds like a lot of work." #!String
    summer_Sat_13: "What? You'd better not be doing that!$a" #!String

The first time the summer_Sat dialogue is chosen, neither response 42 nor 43 will have been given (because this question is the only one which has them as responses), so Haley will say, "Farming sounds so boring... What do you even do all day?" The player can select among these responses:

  • Care for plants
  • Explore the caves
  • Snoop around in your room
  • Dig for treasure

The third response, $r 43 -10 summer_Sat_13#Snoop around in your room, sets response ID 43, reduces Haley's friendship by 10 points, and brings up the dialogue summer_Sat_13 (Haley says, "What? You'd better not be doing that!"). All of the other responses set response ID 42, increase Haley's friendship by 10 points, and bring up the dialogue summer_Sat_12 ("Hmm... sounds like a lot of work.").

The next time summer_Sat is chosen, one of the response IDs listed in the $q command will have been given (either 42 or 43). Therefore, the $q and everything after is scrapped, and dialogue summer_Sat_old is put in its place. This new dialogue uses the $p command to change Haley's dialogue based on whether or not you gave response ID 43 to any previous question. If you answered "Snoop around your room," everything before the | will be used, so Haley will now say, "Farming sounds so boring... Hey, you better not be snooping around in my room anymore!" If response ID 43 has not been given (in this case, you must have given response ID 42, i.e. one of the other three responses to the previous question), everything after the | will be used, so Haley will instead say, "Farming sounds so boring... But I guess it could get you in pretty good shape."

Replacer commands

Replacer commands will be replaced with the relevant string.

@ Farmer's name.
Example: Hi there @!
%adj Random adjective. (Defined in StringsFromCSFiles.xnb)
%noun Random noun. (Defined in StringsFromCSFiles.xnb)
%place Random place name. (Defined in StringsFromCSFiles.xnb)
%spouse The name of Farmer's spouse.
%name A randomly-generated name.
%firstnameletter The first half of the farmer's name (rounded down), like Nat if the farmer's name is Natalie.
%time Current time.
%band The name of Sam and Sebastian's band.
%book The title of Elliott's book.
%rival A random first name of the Farmer's gender from StringsFromCSFiles.xnb (keys Utility.cs.5499 through Utility.cs.5560). Will not match the Farmer's name.
%pet The name of Farmer's pet.
%farm Farm name.
%favorite The Farmer's favorite thing.
%kid1 The name of Farmer's first child.
%kid2 The name of Farmer's second child.

Constants

The game uses these predefined values in some dialogue keys. This section is linked from above where needed.

Days of week

  • Mon
  • Tue
  • Wed
  • Thu
  • Fri
  • Sat
  • Sun

Seasons

  • spring
  • summer
  • fall
  • winter

First/later year

In some cases the game uses a "first/later year" value for dialogue conditions. This only has two possible values:

value meaning
1 Occurs in the first year.
2 Occurs in any year after the first (not only year 2).