Lines and messages
Villagers can say lines you wrote, anywhere in their talk: before their hello, as the hello, as the topic, after it, or as the whole conversation. A talk file, with no code, does it with pools kept to a villager, a season, a time of day, the weather or a calendar day. A Lua script uses the same places, decides in code, and can ask the player a question. The writer path has a kit for the first, and the scripter path has one for the second.
Talk file or script #
Talk file (talk.json) | Script (main.lua) | |
|---|---|---|
| Code | None | Lua |
| Who says it | Everyone, a personality or one villager | Whoever your script picks |
| Where in the talk | Any place: every pool names its "place" | Any place: every line names its place |
| When | Kept to a season, time, weather or calendar day if you like | When your script says, such as only with an item in the pockets |
| A question | No | Yes, in a conversation (ask) |
| How often | chance in 100 talks the pool fits. Nothing is saved. | Your script keeps track, with store if it must last |
| Kit | Villager lines kit | Script kit |
Places in a talk #
A villager's talk is their hello, then a menu of three answers: one about an errand, one to chat, such as "I'm bored!", and "Never mind". Choose to chat, and the villager picks a topic, fresh each time: small talk, a trade, a letter they got, a memory, a hint, or news of an event. Your words can go in five places:
| Place | Where your line goes | What of the game's still plays |
|---|---|---|
before | In front of the hello | All of it: the hello, the menu, the topic |
hello | Instead of the hello. End it so the menu reads well after it. | The menu and the topic. Only an everyday hello is replaced: one with news, such as a bee sting or a finished bug collection, is kept and your line is not said. |
topic | Instead of the topic the game picked, when you choose to chat and it is one of the line's topics | The hello and the menu. The talk ends after your line, as small talk does. |
after | After the topic, as the talk's last message, when you choose to chat | Everything, then your line |
conversation | The whole talk | Nothing: no hello, no menu, no topic. Your pages, then the talk ends. A script may ask a question. |
topics names the topics a topic line may stand in for: small_talk (the weather, the time of
day, the month, plain chat), trade, letter, memory, hint and news. Leave it out for small talk, or write "any" for all six. A trade your line replaces does
not happen: nothing changes hands.
A line is one page, which the game wraps over as many windows as it needs, or a list of 1 to 8 pages. Each page in a list starts on a clean window, after the player presses A.
Talk pools #
A talk file holds pools of lines. Name it in mod.json under content.talk. This is the lines kit's:
"content": {
"talk": "talk.json"
}{
"pools": [
{
"place": "topic",
"lines": [
"Did you hear? The river was extra sparkly this morning.",
"I've been practising my whistling. Want to hear? Maybe later.",
"If you find a shiny rock, tell me first, okay?"
]
},
{
"place": "topic",
"weather": "rain",
"lines": [
"Rain, rain, rain! The puddles are perfect for stomping."
]
},
{
"place": "topic",
"time": "evening",
"lines": [
"The sky goes all orange this time of day. I love it."
]
},
{
"place": "topic",
"personality": "peppy",
"lines": [
"Ooh, it's you! Today is going to be amazing, I can tell!",
"I did ten twirls in a row this morning. Ten!"
]
},
{
"place": "topic",
"personality": "lazy",
"lines": [
"I had a snack, then a nap, then another snack. Busy day."
]
},
{
"place": "topic",
"personality": "cranky",
"lines": [
"Hmph. You again. Well, I suppose that's fine.",
"Back in my day, the trees were taller."
]
},
{
"place": "topic",
"personality": "cranky",
"season": "winter",
"lines": [
"Cold enough to freeze a fish. Don't stand there, it's cold."
]
},
{
"place": "topic",
"villager": "Bob",
"chance": 80,
"lines": [
"Bob here! I've been thinking about lunch all day."
]
}
]
}
A pool's place #
Every pool names its place; there is no default. The kit's pools are topic lines for small talk. This file has one pool for each place:
{
"pools": [
{ "place": "before", "chance": 20, "lines": ["Psst! Over here!"] },
{ "place": "hello", "weather": "rain", "lines": [["Oh, hi! Isn't the rain\nlovely?", "The flowers think so."]] },
{ "place": "topic", "topics": ["trade", "small_talk"], "lines": ["No deals today. Let's\njust talk."] },
{ "place": "after", "time": "evening", "lines": ["Getting late. Get home\nsafe!"] },
{ "place": "conversation", "villager": "Bob", "day": "bob-day", "lines": [["It's Bob Day! The whole\ntown knows it.", "Well, I know it. Bye!"]] }
]
}- Every talk is asked again, so the same villager can say several of your lines in one day.
- A villager never says the same line twice running when the pools hold another.
- A conversation pool takes the whole talk when it fits and its
chancerolls yes. Keep it rare, or to one villager or one day.
The keys of a pool #
Each pool has lines. Every other key is optional and keeps the pool to a villager or a moment:
{
"pools": [
{ "place": "topic", "personality": "cranky", "lines": ["Hmph. Another day of\nyou walking around.", "What now? I was just\ngetting comfortable."] },
{ "place": "topic", "weather": "rain", "lines": ["Rain again. The flowers\nare loving it, at least."] },
{ "place": "topic", "season": "fall", "time": "evening", "chance": 30, "lines": ["The evenings come so\nearly now. I like it."] }
]
}linesis 1 to 32 lines. A line is a page of 1 to 160 characters, with at most 3 line breaks, written\n, or a list of 1 to 8 such pages. The game wraps a page for you, see how a line is shown.placeisbefore,hello,topic,afterorconversation, and every pool needs one.topicsgoes only withtopic.personalityis one of normal, peppy, lazy, jock, cranky and snooty.villageris one villager's name, in any case. A pool has apersonalityor avillageror neither, never both. With neither, it is for everyone.seasonis spring (March to May), summer (June to August), fall (September to November) or winter (December to February).timeis one of the game's own four: morning (5 to 12), day (12 to 17), evening (17 to midnight) and night (midnight to 5).weatheris clear, rain or snow. Cherry blossom and falling leaves count as clear.dayis theidof a day in your mod's calendar file. The pool fits only on that day.chanceis 1 to 100: in how many talks in 100 the pool's line is said, when the pool fits. Leave it out and the pool says it every time it fits. For a topic line, the game picks small talk on roughly one chat in four or five (more often with a happy villager), so a lowerchanceleaves room for the game's own.- A file holds 1 to 32 pools.
How a line is picked #
- Each place is picked on its own, from the pools of that place. A topic line also needs the game's topic to be one of its
topics. - The game takes the most specific pools that fit: those kept to today's calendar
day, then the villager's own by name, else their personality's, else everyone's. Only that level counts. - A pool fits when its
season,time,weatherandday, the ones it names, are the ones now. A pool that names none of them always fits. - Each pool that fits rolls its
chance. - The lines of the pools that pass, from every mod, are put together, and one is picked.
- When every pool at that level rolls no, that part of the talk stays the game's. The less specific pools are not asked instead.
In the kit, a peppy villager says a peppy line, and a jock says a line for everyone, because no pool names jocks. Bob
has his own pool with a chance of 80, so in most of his small talks he says his line, and in the rest
he makes the game's own small talk.
- Between mods, pools are not ranked by load order. Every mod's lines at the same level go in together.
- Nothing is saved. There is no record of who said what, so a restart changes nothing.
- Pools work in either scope, and in The City too.
Calendar days #
A pool with a day speaks only on that calendar day,
in its place, and on the day it comes ahead of every pool kept to no day, villager and personality pools too. Give
it a chance to leave room for the other pools and the game's own talk. A calendar day needs no notice or
letter to be named by a pool.
Where a line never appears #
- A topic or after line, in a talk where you pick the errand answer or "Never mind". Only the chat answer leads to a topic.
- A first meeting.
- An errand, delivery or contest going with the player.
- A villager moving out.
- The first-job errands, and a new player's first ten chats: those topics are tips from the villagers, one a chat, until all ten are given.
- A pitfall or a bee chase.
- An islander.
- The "should I move?" topic of a villager who is thinking of leaving.
- The menu. Its three answers are the game's.
When to use a script #
To say something only when something in the game is true, such as an item in the pockets, or to ask the player a question and answer what they pick, use a script. See Saying a line with villager_talked below.
The messages file #
A script's lines go in a messages file, a JSON file of keys and lines. A script reads one with message("key"). Name the file in mod.json under content.messages. Call it messages.json and keep it at the top of the mod, next to mod.json. This is the script kit's:
"content": {
"messages": "messages.json"
}{
"apple": "Is that an apple in your pockets? It smells wonderful!",
"first_fish": "My first fish of the day!",
"fair": "It's the Harvest Fair today. I should take some fruit to town."
}
- A key is 1 to 48 characters. It uses only lower case letters, digits,
_,.and-. - A mod holds up to 256 keys.
- Each line is 1 to 400 bytes. An English letter is one byte. Accented letters and other alphabets take more.
- Inside a line,
\nstarts a new line and\"is a quote mark. - A key's full name is
your-id:key. Two mods can both have anapplekey without clashing.
Reference: messages file, with every field, limit and error code.
How a line is shown #
- The game wraps a line by its width, not by counting characters. One line holds 180 pixels of the game's font, which is about 24 letters. Narrow letters like i and l fit more. Wide letters like W and m fit fewer.
- A page holds 4 lines. A long text runs over several pages, and the player presses A to read on.
- A text that only just spills over leaves a last page with one word on it. Read your lines in the game.
- A character the game's font does not have shows as
?. Plain English letters, digits and common punctuation are safe. Test anything else. - Each page in a list of pages starts a clean window. A page of a hello or a question is best kept short.
- Lines are for ordinary talks only. A special talk never reaches mods. Examples are a first meeting, a villager moving out, an errand in progress and a complaint. The villager's next ordinary talk reaches mods as usual.
The characters the game draws #
The game's font draws every printable ASCII character in a line except $ * ^ | \, which each show as ?. [ ] { } show as parentheses. It also draws these: ¿ Ä À Á Â Ã Å Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö Ù Ú Û Ü ß Þ à á â ã ä å ç è é ê ë ì í î ï · ð ñ ò ó ô õ ö ù ú û ü ý ÿ þ Ý § ª º µ ³ ² ¹ Æ æ « » × ÷. Curly quotes, dashes and the ellipsis become their plain spelling.
Anything else shows as ?, such as an emoji or a Polish or Greek letter. Letters and board notices take
plain ASCII only.
Saying a line with villager_talked #
A messages file does nothing on its own. A script picks a line and returns it from a villager_talked handler. The event's e.villager table has the villager's name and a number, id,
that stays the same for that villager.
on("villager_talked", function(e)
return { place = "before", line = "Oh, it's you! " .. e.villager.name .. " is always glad to see you." }
end)Every line names its place: a plain string returned alone is refused, and the Mod log says so. To use a line from your messages file, call message("key"). It returns the line, or nil if there is no such key.
Any place from a script #
Return a talk table, { place, line, topics, ask }, or a list of them, one a place. place is required. line is a string or a list of 1 to 8 pages.
on("villager_talked", function(e)
return {
{ place = "hello", line = { "Hi, " .. e.villager.name .. " here!", "Nice day, right?" } },
{ place = "topic", topics = "any", line = "Let's skip the news." },
{ place = "after", line = "See you around!" },
}
end)- The topic and after lines are said only if the player chooses to chat. A topic line also needs the game's topic to be one of its
topics. - A table that is not right, such as an unknown place, is written to the Mod log and nothing of it is said.
A conversation that asks #
A conversation may end in ask = { text, choices }, a question with 2 to 4 answers of up
to 16 characters. The player's pick goes to your villager_answered handler, with e.villager, e.choice (counting from 1) and e.text. Return what the villager says
next: a line, or { line, ask } to ask again. Return nil and the talk ends. List villager_answered in scripts.events.
on("villager_talked", function(e)
return {
place = "conversation",
line = "I baked today.",
ask = { text = "Tea or cake?", choices = { "Tea", "Cake" } },
}
end)
on("villager_answered", function(e)
if e.text == "Cake" then
return { line = "Cake it is!", ask = { text = "A big slice?", choices = { "Yes", "No" } } }
end
if e.text == "Yes" then return "Enjoy!" end
return "Tea, then. Lovely."
end)A line that depends on something #
This is the talk part of the script kit. A villager notices an apple in your
pockets, once a day each. APPLE is 0x2800, the apple's item number.
local noticed = {} -- villagers who noticed an apple, by id
local noticed_on = nil -- the day that list is for
local function holding(item)
for _, p in ipairs(game.pockets()) do
if p.item == item then return true end
end
return false
end
-- "notice" is a setting in mod.json, which the player turns on or off on
-- the Mods tab. settings.get reads it. This is a Just you mod, so a setting's
-- "scope" changes nothing a visit sees, and it is left out.
-- The handler returns a talk table, and every line names its place: here
-- "before", said before the villager's hello. The others are "hello" (instead
-- of the hello), "topic" and "after" (when you chat), and "conversation" for
-- the whole talk (with an ask, the player's pick comes to villager_answered).
-- A plain string with no place is refused. A line can be a list of pages:
-- line = { "Page one.", "Page two." }.
on("villager_talked", function(e)
if not settings.get("notice") then return nil end
if noticed_on ~= game.day_number() then
noticed, noticed_on = {}, game.day_number()
end
if noticed[e.villager.id] or not holding(APPLE) then return nil end
noticed[e.villager.id] = true
return { place = "before", line = message("apple") }
end)game.pockets()lists what you hold, one table per item with itsslotanditem.- With no apple, the handler returns
nil. The talk then goes to the next mod's script. game.day_number()goes up by one each game day, so the list of who noticed starts again each day. The list is kept in memory, so it is also empty after a restart.- The same shape works for the time with
game.time(), the town and season withgame.town(), and anything your script saved withstore.
Lines from another mod #
A full key with a colon reads another mod's line. If that mod is not installed or is switched off, you get nil. Always check:
on("villager_talked", function(e)
local contest = message("example.harvest-post:contest") -- nil if Harvest Post is not installed
if contest then
return { place = "after", line = contest }
end
return nil
end)When two mods want the same talk #
- Each place takes one line a talk.
- Scripts come first. Every script's
villager_talkedruns, in the order of the Mods tab list, from the top. The first line returned for a place takes it. A later script's line for that place is written to its Mod log and not said. - A conversation needs every place free, and then takes the whole talk: the scripts below it are not asked.
- Then the pools fill each place no script took. Pools are not ranked by order: the lines of every mod are put together and one is picked.
- A conversation pool is used only when no script took any place.
Return nil when you have nothing to say, so other mods get their turn.