Skip to content

Co-op

Co-op in PokeLoom means several players in one game world at once. It is designed as one engine feature that every game can turn on with settings, and that scales from two friends on one desktop to eight players online. This page is how it works and what a creator sets. The wider picture of playing together is on Multiplayer overview.

In a shared field every player’s character is in one world, simulated once from everyone’s inputs. Each tick the world takes one input a player, in player order, and steps every player’s character. Because the engine is deterministic, the same inputs give the same world on every machine; on one machine there is nothing to send at all.

That is what lets players touch the same things: stand on two plates at once, push the same boulder, block a person’s path for each other. Up to 8 players fit one field. That number is worked out from first principles (plan 43): the internet’s delay between the slowest players and the DS’s room for drawn figures on its busiest maps both allow about eight, and one cap on every platform means a game that works on a LAN also works online.

On a desktop, two players can play one game at once:

  • Inputs. The keyboard is the first player. A second key set (named with p2. in the desktop’s config file) is the second. The first two gamepads are a player each. More pads play nobody: one machine has at most two local players.
  • Joining. A game with [coop] lets a second player press START to join while max_players has room. The new player appears beside the first.
  • Who does what. The Start menu, field moves, wild encounters and step counts are the first player’s. A second player’s START joins rather than opening the menu.
  • Warps take everyone. One machine holds one area, so a warp taken by any player takes all of them; the others arrive behind and beside the first.
  • Replays. The other players’ inputs are kept in the input log as changes, so a session replays exactly, and a one-player log is the same, byte for byte, as before.

A DS has one set of buttons, so a DS is one player. Two DS play together over a link.

Planned (decision 321): two players on one desktop see two consoles side by side, each with its own two screens, field view and menus. Today they share one view.

Every step, talk, sign and trigger is made by a player, and a script knows which. A script started by a player’s step runs with trigger meaning that player, and the script rows count and name players:

Row Value
players how many players are in the field
playerson x, y, w, h how many players stand in a rectangle
triggerplayer the player (0 the first) whose step, talk or reading started the script
leash cells sets how far a player may go from the players’ middle

The actors player2 to player8 and trigger can be moved, faced and followed by the camera like any actor. A puzzle that needs two players is a few lines. This one, from the engine’s co-op test project, opens a gate when a player stands on each of two plates at once:

hide gate when var(41) == 1
script plates {
if var(41) == 0 && playerson(12, 17) + playerson(19, 17) == 2 {
var(41) = 1
move gate, [right, vanish]
say "The gate opens."
closetext
}
}
on step area(12, 17) {
call plates
}
on step area(19, 17) {
call plates
}

The full list is in the script reference.

With several players on one screen, the camera looks at the middle of the group. The leash keeps the group together: a player cannot step further than leash cells from the players’ middle. With camera = "zoom" the camera also pulls back to fit everyone, by at most zoom_max cells of distance, before the leash holds them.

A field is small: the DS’s top screen shows about sixteen cells across. With many players in view, people hide behind players and corridors jam. From crowd.at players in view, the crowd rules apply: how the other players look, whether players block each other, whose followers are drawn and whether names are shown. By default players pass through each other in a crowd, so nobody is trapped in a one-cell passage.

[coop] in game.toml turns co-op on; without it the game is for one player and spends nothing on the feature. The engine’s co-op test project uses:

[coop]
max_players = 2
leash = 12
Key What it sets
mode field (players share one field) or off
max_players 1 to 8
couch whether several local pads play on one desktop
leash cells from the players’ middle; 0 for none
camera leash (one view on the middle) or zoom (pulls back to fit)
zoom_max cells of distance the zoom may add
[coop.crowd] at, others (solid, ghost, hidden), ghost_alpha, collide, names, followers

Every key, its range and its default are in the game.toml reference. Of the crowd’s looks, hidden works today; ghosts drawn see-through and name tags over players are read but not yet drawn.

Everything below is planned (plan 43, as rows O21 to O24 of plan 33’s order).

The shared field online. Each machine runs the whole world. Every tick each player sends their input, two to four bytes; a machine steps a tick once it has every player’s input for it. Inputs are taken a few ticks early to hide the network’s delay; a walking step is long enough that the delay reads as the original games’ own start-of-step pause. Menu results, a battle’s outcome, saves and pauses enter the same stream as actions at a tick. Every second, each machine compares a digest of its world with the others’; a mismatch is resolved from the session’s authority and reported.

Joining and leaving. A late joiner receives a snapshot of the world while everyone pauses for a moment. A player who stops sending is waited for, then dropped; in a battle the AI takes their seat. Reconnecting is a late join. There is no host to migrate: every machine holds the whole session.

Per-player state. Party, bag, money, boxes and dex are always each player’s own. A script declares which flags are each player’s (own) and which a shared room keeps. Items on the ground and beaten trainers are, by a crowd setting, either taken once for everyone or once by each player.

Battles as setup records. A co-op battle is a record: its format, its foes, how many human seats, who joins (the trigger, those near, everyone, or whoever accepts a card), how an empty seat is filled, whether players share one encounter or each fight their own, who may catch, whether it is gone for everyone afterwards, rewards, a choice timer, spectators and what happens when a player drops. A battle holds at most two humans a side, Showdown’s multi shape. A legendary can be one prize, one each, or one fight each, by three values of the record. The world keeps running for the players who are not in the battle.

Dialogue and cutscenes. A message shows to a scope (the trigger, those near, everyone). Who answers a question is set per scene: the trigger, the first to press, a vote, or the host. A skippable scene asks for a skip vote by a rule. Players who missed a scene can be given its key items, or replay it.

Saves. Saving is an action every machine performs at the same tick, each writing its own copy: the shared world and every player’s record. Any member can continue the session from their copy; the newest save wins. A player who leaves keeps their own record.

Together mode (plan 43, plan 33): rooms of up to 16 where each player runs their own world and sees the others as presence, sharing only declared flags, variables and events. A map marked as shared turns the players on it into a shared field.

A DS is one player. Co-op on DS is two or more DS linked, or a DS linked with a desktop, through the same lockstep. The co-op test project’s session replays a recorded second player’s inputs on the DS to check that the world comes out the same; that session is written and has not yet been run in melonDS. The online link between a desktop and melonDS stalls today (see The server and online play).

The cost on the DS is small: the world’s room for guests is about 0.6 KB of heap, and the co-op code added about 6 KB to the DS build.