How mods work

The ideas every mod shares.

A mod is a ZIP #

A mod is a ZIP file with a mod.json in it. A typical one looks like this:

my-mod.zip
my-mod.zip
├── mod.json            required
├── textures/           .dds pictures (texture mods)
├── messages.json       lines, by key
├── shops.json          shops, by shop id (World mods)
└── main.lua            a script
  • mod.json sits at the top of the ZIP, or inside one folder at the top. The game ignores that folder, so zipping a folder works.
  • A mod holds only .json, .lua, .dds, .png, .txt and .md files. Any other kind is refused.
  • File and folder names use plain ASCII letters, digits and punctuation. A name cannot contain \ or :, and a folder cannot be named . or ...
  • Two names that differ only in upper and lower case are refused.
  • The game ignores a mod repository's own files in any ZIP: hidden files and folders (a name starting with a dot, such as .git, .github, .gitignore, .vscode, .playac and .DS_Store), __MACOSX, Thumbs.db and node_modules anywhere, and at the top of the mod README.md, CHANGELOG.md, LICENSE or LICENCE with any extension and the media/ folder. It drops them before it checks anything, keeps none of them and counts none toward a limit. So a Finder or Explorer ZIP of a whole mod repository works as it is.
  • A JSON file that has the same key twice is refused.

mod.json #

This example has every field:

mod.json
{
  "schema": 1,
  "api": 1,
  "id": "yourname.my-mod",
  "name": "My Mod",
  "version": "1.0.0",
  "authors": ["yourname"],
  "description": "What it does.",
  "scope": "client",
  "content": {
    "textures": "textures/",
    "messages": "messages.json"
  },
  "scripts": {
    "main": "main.lua",
    "events": ["villager_talked", "day_started"]
  },
  "assets_original": true
}
FieldRequiredRule
schemayesAlways 1.
apiyesThe API level the mod is made for. It is a whole number, and it is 1. See API levels.
idyesYour name, a dot, the mod's name. See ids.
nameyes1 to 60 characters. Shown in the Mods tab and the mod list.
versionyesThree whole numbers with dots, like 1.0.0 or 2.13.4. A leading zero is refused, so 1.02.0 does not work.
authorsyesA list of 1 to 8 names, each 1 to 40 characters.
descriptionnoUp to 500 characters.
tagsnoUp to 5 different tags. Players filter the mod list by them, and the game never reads them. The tags are textures, clothing, furniture, scenery, villagers, dialogue, shops, seasonal, holidays, quality-of-life, humor, accessibility and scripts. Anything else is refused.
scopeyes"client" or "world". See scope.
contentnoAny of "textures", "messages", "shops", "items", "letters", "calendar" and "talk". textures is a folder with at least one file. The others are files. messages is one .json file. Each path must be in the ZIP. Any other key is refused.
scriptsnomain is a .lua file in the ZIP. events lists one or more events, each once: villager_talked, day_started, item_picked_up, scene_entered, data_migrated, hour_changed, item_bought, item_sold, fish_caught, bug_caught, letter_read, villager_moved_in, visitor_arrived, command_finished, question_answered, timer_fired, villager_answered, button_pressed, button_released and player_acted. Nothing else goes inside scripts.
permissionsnoThe commands the mod's script may queue, each once. The game refuses any command the list leaves out. The Mods tab and the moderators' review show what the list lets the mod do. take_item and take_bells let the mod ask the player for items or Bells. The game itself shows the question with the true item and amount, and nothing is taken unless the player says yes. save lets the mod save the town where the player could save at Gyroid. play_sound lets the mod play the game's own sound effects, heard only by its own player. set_weather sets the town's weather for the day, and set_shop_goods and set_shop_open change a shop for the day. The three need scope world. set_hat and set_shirt change only how the player's hat or shirt looks on their own screen and work in any mod. react plays one of the reactions on the player's own character and works in any mod. Needs scripts.
exportsnoA library's remote functions by name, each with a one-line description. These are what other mods may remote.call. At most 32 names, each 1 to 32 of a-z 0-9 _. Each description is 1 to 120 characters on one line. When exports is declared, the game lets remote.add offer only these names. The Mod log says when a listed name was never offered. Needs scripts.
renamesnoMaps an old full item id of this mod to the full id of an item in this mod's items file. At most 64. Needs content.items. Each rename runs once per save, and mod-items.json records it. A renamed item already in a house therefore keeps working.
dependsnoMods this one needs, as mod id to version range. A range is "*", or up to 4 comparisons (>= <= > < = and a version) split by one space. At most 16. This mod loads after them. It does not load when one is missing, off, out of range or not loading. The game checks again when it starts: a mod whose dependency is not loaded before it, in range, is not loaded at all.
optional_dependsnoMods this one can use but does not need, as mod id to version range. Ranges are written as in depends. At most 16. This mod always loads. An optional dependency is present when it is installed, switched on, loading and inside the range. A present one loads before this mod. One that is missing, off, not loading or outside the range is absent, and nothing waits for it. A script asks with remote.version(id). remote.call to an absent one returns nil, a message and a code. It is not an error. A mod id may be in only one of depends, optional_depends and conflicts.
conflictsnoMods this one cannot run with, as mod id to version range. At most 16. A mod id may be in only one of depends, optional_depends and conflicts. This mod stays off while a matching one is on.
data_versionnoA whole number 1 to 1000000 for the shape of what the scripts save. When it changes, the data_migrated event runs once per town. Listing data_migrated in scripts.events needs it.
settingsnoAt most 16 settings the player sets on the Mods tab and scripts read with settings.get. The types are bool, number (whole, with min and max), choice (2 to 16 choices) and text (max_length 1 to 200). A setting may say "scope". "world" is the default: the value is part of the town, a friend visit compares it, and a visitor lent the mod runs the host's value. "client" is the player's own: it is never compared or sent, and each player keeps theirs on a visit. Use client for a choice that only changes what its own player sees or hears.
assets_originalyesMust be true. It is your promise that every file is your own work.
  • "game" and "save" are reserved. A mod.json with either is refused, even when the value is null.
  • A key the game does not know is refused, and the message names the closest key: mod.json: unknown key "permisions" (did you mean "permissions"?).
  • The shops, items, letters, calendar and talk files refuse unknown keys the same way. A messages file does not, because every key there is a line.
  • A "$schema" line for your editor is a known key.
  • Keys are case-sensitive. Name is not name.

Ids and namespaces #

  • An id is author.mod-name. Each part uses lower case letters, digits and dashes, and starts with a letter or digit. The part before the dot has up to 32 characters, and the part after has up to 48.
  • The id is how the game tells mods apart. Installing a ZIP with an id you already have replaces that mod and keeps its place in the list.
  • Your lines are named id:key, such as sam.gossip:line1, so two mods never clash over a key.
  • The mod list keeps the author names playaconline, official, admin and example for the site. You can use them at home, but an upload with one is refused.
  • The first account to share an id owns it. Only that account can share new versions of it.

Scope #

A Just you mod ("scope": "client") changes the game only for the player who installed it. A World mod ("scope": "world") changes the town, so visitors see it too.

Just you mod, "client"World mod, "world"
Who sees itOnly the player who installed it.Anyone in the town, visitors too.
Can holdEverything except a shop, a bulletin board notice, a script that sets the weather or a script that changes a shop.Everything. Only a World mod can hold a shop, a bulletin board notice, a script that sets the weather or a script that changes a shop.
Friend visitsNever matter.A World mod counts when it has textures, shops or items content. One with only lines, letters, calendar days, talk pools or a script does not count. Both towns need the same World mods that count, in the same versions and the same order. There is one exception. When every one of the host's is a reviewed version from the mod list, the visitor can load them for that visit. Every world setting of a World mod that counts is part of the match. A setting marked "scope": "client" is the player's own and is not. See world settings and client settings.
In The CityIts textures, lines and scripts keep running. Its mod items are off, and every command is refused there.Its shops, board notices and mod items switch off. Its textures, lines and scripts keep running, but every command is refused there.

Use "client" unless your mod has a shop, a bulletin board notice, a script that sets the weather or a script that changes a shop. Those change the town a visitor sees, so a Just you mod with one is refused. See Multiplayer for the full visit rules.

API levels and compatibility #

  • The api number says which rules your mod was written for. The game runs level 1, and a mod says "api": 1. The changelog lists what the level holds.
  • When a change would break existing mods, we add a new level. Mods made for the old level keep working by the old level's rules while the game still supports it.
  • A mod for a level the game no longer runs is not loaded. Its row says made for an older game.
  • A mod for a newer level than the game knows is not loaded either. Its row says needs a newer game. Other mods are not affected.
  • A level is read for at least 12 months after the next level ships.
  • Before a feature goes, it is marked deprecated for at least two more levels and at least 90 days, whichever is later. The changelog says how to move your mod up.
  • We promise only what these docs and the reference describe. Anything else your mod finds by experiment may change without notice.

When mods load #

  • The game reads mods once, when it starts. Installing, removing, switching or reordering a mod needs a restart. The Mods tab offers Restart now.
  • A mod that cannot be read at start is skipped, and its row says why. The other mods still load.
  • If a mod stops the game from starting, choose Start without mods in the Mods tab. Adding ?nomods=1 to the end of the play page's address does the same. Either starts the game once with every mod off.
  • If the game stops responding while it starts with mods on, the next start runs once without them and names the mods that were on. If it stops responding later, during play, that takes two sessions in a row. Nothing is switched off for you. Reloading or closing the tab does not trigger it.
  • No mod runs in the title screen demo.

Load order #

Mods load in the order the Mods tab lists them. The arrows on each row move it. The table says which mod wins when two mods change the same thing.

ContentTwo mods change the same thing
A textureThe lower mod in the list wins, because it loads last. Any mod wins over the HD texture pack.
A shop (the flower shop, Nook's, any shop id)The lower mod in the list wins that shop whole, because it loads last. Two mods that change different shops both apply.
A place in a villager talk (a script's villager_talked)The highest mod whose script returns a line for that place takes it. A conversation takes the whole talk, and mods below it are not asked.
command_finished, question_answered, data_migrated, timer_fired and villager_answeredEach goes to one mod. A command's result and an answer go to the mod that asked. data_migrated goes to the mod whose data version moved. timer_fired goes to the mod that set the timer. villager_answered goes to the mod whose conversation asked.
Every other event (14 of them)Every mod's handlers run, top to bottom.
  • A texture or a shop has one slot. Each mod writes over the mod above it, so the lowest mod in the list wins. Nook's stock follows the same rule.
  • For a script's talk lines, the game asks each mod in turn, and the first line for each place takes it. The highest mod wins a place.
  • Move a mod down to make its shop win. Move it up to make its script's lines win.
  • Talk pools are not ranked. They fill the places no script took, and one line is picked from every mod's fitting lines for that place.

Limits #

Sizes here are binary. 1 MB is 1,048,576 bytes and 1 KB is 1,024 bytes.

WhatLimit
Files in a mod2000
ZIP size16 MB
Unpacked size of a mod64 MB
mod.json64 KB
Any other .json256 KB
Any .lua512 KB
A file path inside the mod160 bytes, ASCII
Mods switched on at once32
Unpacked size of all switched-on mods96 MB on a computer, 24 MB on a phone or low-memory device
A .png2048 x 2048 pixels
A .ddsUp to 16384 pixels a side, one level (no mipmaps)
Message keys256 per messages file, each 1 to 48 of a-z 0-9 _ . -
A line1 to 400 bytes. The game shows 24 characters a line and 4 lines a page.
Shop name1 to 40 characters, one line
Shop line (a greeting, a stock line)1 to 160 characters, at most 3 line breaks; a slot holds 1 to 8 lines
Shop blocks1 to 8 for one shop
Shop goods in a block1 to 6 at the flower shop, 1 to 16 at Nook's, 1 to 6 at a visiting seller. A price is 1 to 99999 Bells.
Script memory4 MB per mod, 16 MB for all mods together
Script time200,000 Lua instructions per mod per event. Library work counts too. That count is what stops a script, the same on every device. Wall-clock time is a backstop: one event run past 125 ms, or 3 runs in a row over 8 ms, also stop it, and a slow device stretches both. The main chunk at start has a 250 ms backstop.
Handlers16 per event per mod
log()20 lines per event, 500 per session
store8 KB per town, and 8 KB in store.client. A key is up to 64 bytes and a text value up to 1024 bytes.
Commands4 per event. Each game day, per mod in each town: 3 letters, 5 items, 20 lines and 10 questions. The day limit is per town, for all of its residents together.
New items64 per mod, 512 across all mods
Settings, dependencies16 settings, 16 depends per mod
A talk line from a scriptUp to 400 bytes
Uploads5 an hour, 10 waiting for review at once, 64 MB stored per account

Saved data #

  • Each mod has a store per town. It holds text, numbers and true/false values under keys, up to 8 KB per town.
  • The store travels with the town. It is in the cloud save, in backups and in Export with mod data under the save button's More options.
  • A town has up to 4 residents, and they share store. store.player is per mod, per town and per player, inside the same 8 KB.
  • store.client belongs to the browser, whatever town is loaded.
  • Every store.set, store.player.set and store.client.set writes the mod's file in the save folder before it returns.
  • The browser keeps the save folder at the game's next save sync. That happens at a game save. For the cloud, mod data also uploads at most every 2 minutes. A tab closed before the sync loses the last sets.
  • Whole numbers come back as whole numbers.
  • A store.set that would go over 8 KB changes nothing and raises an error. So does a key or value over its limit. Unless you call it inside pcall, that error stops your script.
  • Removing a mod asks the player whether to keep its data or delete it. See Per-town data.

The safety model #

Players install mods from strangers. So a mod can do much less than code in a normal program.

  • Scripts have no io, os, debug or package libraries. They have no load, dofile, loadfile, require, collectgarbage or print. A script cannot read files, use the network or load more code.
  • Scripts are read as text only. Compiled Lua bytecode is refused.
  • Each mod's script runs in its own Lua state, under memory and time limits. A script that goes over is stopped for the session, and the rest of the game carries on.
  • Scripts answer events with data. A script cannot change the game from inside an event. A command (cmd.*) only queues a change.
  • The game applies queued commands at the end of a frame's update, before the frame is drawn, while the player is free. So a mod cannot corrupt a save in the middle of a frame.
  • Mods never patch the game's code or read its memory, and never will.
  • Mods live in the player's browser storage and are read once at start. A mod cannot see the player's account, files or anything else on the page.
  • A moderator reviews every version of every shared mod, pictures included, before it is listed. A mod installed from a file is never uploaded, so nobody has reviewed it.
  • The game checks its mods against the mod list at every start. A removed version is switched off for everyone who has it at their next check.
  • The check never holds the game up for long. When the game is offline or the check is too slow, the game goes by the last check in that browser. A version that was removed stays off, and so do all mods if mods were switched off for everyone. A mod the game has no word on runs as before, so offline play keeps working.

The life of a shared version #

Each version you share moves through these states:

StateIn the mod listNew installsCopies already installed
Waiting for reviewNoNoOnly you have it
ListedYesYesRun
Older version (a newer version is listed)No, the newer one isNoRun, and show Update available
Withdrawn (by you or a moderator)NoNoRun, and say it was withdrawn. Friends who both have it can still visit each other. A version you withdrew yourself can still be lent to a friend for a visit. A version a moderator withdrew cannot.
RemovedNoNoSwitched off at the next start, with the reason. Offline, it stays off. We delete its files from the site, except as evidence for a child-safety report.
RefusedNoNoNot applicable. We delete its files from the site.
  • A version number cannot be reused once it is waiting, listed or removed. Share a fix as a higher version.
  • A refused version may be fixed and shared again under the same number.
  • A removal also switches off the same files installed from a ZIP, because the game matches mods by their contents.
  • You can withdraw a version yourself under Share a mod in the Mods tab. See Publishing, withdraw a version.
  • A withdrawn or older version stays downloadable at /api/mods/blob/<sha256>. That address never changes.
  • /api/mods/by-content/<content hash> finds a version from the content hash a friend visit reports.