round
`puttCourse.round` runs a multi-hole stroke-play round of mini golf for any number of players. Game code creates a round from an ordered list of holes (`Round.new{ holes = {...}, players = "peers" }`). Everyone plays at the same time, each player on their own current hole. The ro…
round
puttCourse.round runs a multi-hole stroke-play round of mini golf for any number of players. Game code creates a round from an ordered list of holes (Round.new{ holes = {...}, players = "peers" }). Everyone plays at the same time, each player on their own current hole. The round counts strokes from the course balls (or from your own shot / penalty / holed calls), adds water and out-of-bounds penalties, caps a hole at par + maxOverPar (the ball goes into the cup and the hole is finished), gives stars per hole, places each player's ball on their next tee, can wait for everyone before moving on (waitForAll), lets players join and leave mid-round, restarts, and ends with a ranking (lowest total, then most stars).
Events: holeStarted, shot, penalty, holeFinished {player, hole, strokes, par, toPar, stars, holeInOne, capped}, roundFinished {ranking}, playerJoined, playerLeft, roundStarted, roundRestarted.
Multiplayer: in play the state sits on a synced PuttRound_<id> entity with a RoundState component. Its owner is the one authority that applies the rules; the engine hands it to a peer that stays when the owner leaves. See the package README for the full API.
Interface
What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.
conforms to
zero/source-extract/v2puttCourse.round: multi-hole stroke play for any number of players. A round is an ordered list of holes; every player plays at the same time, each on their own current hole. Strokes come from the course balls (ballStruck, ballInWater, ballOutOfBounds, ballInCup, ballStopped) or from your own calls (shot, penalty, holed), penalties are added, a hole is capped at par + maxOverPar (the ball goes in the cup and the hole is finished), stars are given per hole, each player's ball goes to the next tee, and the round ends with a ranking (lowest total, then most stars).
myPeer( ) → any
deepCopy(v: any) → any
| arg | type | description |
|---|---|---|
| v | any |
sameId(a: any, b: any) → boolean
| arg | type | description |
|---|---|---|
| a | any | |
| b | any |
stars(rule: any, strokes: number, par: number, info: any?) → number
Stars for one hole under a rule. rule: a function(strokes, par, info) -> number, or a table { holeInOne, under, par, over, capped } (missing keys take Round.DEFAULT_STARS). info: { holeInOne, capped }.
| arg | type | description |
|---|---|---|
| rule | any | |
| strokes | number | |
| par | number | |
| info | any? |
pick(k: string) → number
| arg | type | description |
|---|---|---|
| k | string |
rank(players: { any }, holeCount: number) → void
Rank player records: those who played every hole first, then lowest total, then most stars, then who joined first. Ties share a place. Answers { place, player, name, colour, total, toPar, stars, holes, complete, left }.
| arg | type | description |
|---|---|---|
| players | { any } | |
| holeCount | number |
hookNet( ) → void
holeIdOf(h: any) → string
| arg | type | description |
|---|---|---|
| h | any |
new(opts: any?) → any
Start a stroke-play round. opts: id ("round"): the same id on every machine; Round.new with an id already live replaces that round. holes: ordered list of hole handles (Course.buildHole) or hole ids. Pars come from the holes (or pars = { ... } for ids of holes not built yet). players: list of player ids or { id, name, colour } tables, or "peers" (every machine in the session is a player, joining and leaving with it). Add more with round:addPlayer at any time. maxOverPar (3): a hole is capped at par + maxOverPar strokes (false: no cap). stars: Round.DEFAULT_STARS-shaped table or function(strokes, par, info) -> number. waitForAll (false): a player who holed out waits on that hole until every player has finished it. advanceDelay (1.5 s): pause between finishing a hole and starting the next one. capDelay (6 s): after the capping stroke, the hole is finished when the ball stops, lands in a hazard, or after this many seconds. placeBalls (true): each machine puts the balls it owns on their player's next tee (and in the cup when capped). joinAt ("first"): a player joining mid-round starts at hole 1, or "current": at the lowest hole an active player is on, earlier holes scored as capped with 0 stars ("skipped"). listenCourse (true): count strokes from the course ball events. synced (true in play): keep the state on a synced RoundState entity. scoreKit (nil): pass scoreKit's module (require("scoreKit.score")) and the stars won on each hole are added to the player's score. The round never requires scoreKit itself. autoStart (true): start at once (else call round:start()).
| arg | type | description |
|---|---|---|
| opts | any? |
get(id: string?) → any
A live round by id.
| arg | type | description |
|---|---|---|
| id | string? |
all( ) → void
Every live round, by id.
_bindEntity(self: any) → void
| arg | type | description |
|---|---|---|
| self | any |
_isHost(self: any) → boolean
the peer that creates the synced entity: the lowest peer id in the session
| arg | type | description |
|---|---|---|
| self | any |
_component(self: any) → any
| arg | type | description |
|---|---|---|
| self | any |
isAuthority(self: any) → boolean
True on the machine that applies the round's rules (the owner of the synced entity, or this machine when the round is local).
| arg | type | description |
|---|---|---|
| self | any |
_commit(self: any) → void
| arg | type | description |
|---|---|---|
| self | any |
state(self: any) → any
The round state (read it, never write it): { id, phase ("waiting" | "playing" | "finished"), epoch, holes = { { id, par, number } }, players = { record }, ranking, maxOverPar }. A player record: { id, name, colour, order, left, hole (index; holes + 1 once done), status ("playing" | "holed" | "finished"), strokes = {per hole}, penalties = {per hole}, stars = {per hole}, pars = {per hole}, result = {per hole: "" | "holed" | "capped" | "skipped"} }.
| arg | type | description |
|---|---|---|
| self | any |
on(self: any, name: string, fn: (any) → void
Listen to a round event ("*" for all): holeStarted, shot, penalty, holeFinished, roundFinished, playerJoined, playerLeft, roundStarted, roundRestarted. Every machine hears each one once. Answers a function that stops listening.
| arg | type | description |
|---|---|---|
| self | any | |
| name | string | |
| fn | (any |
_dispatch(self: any, name: string, ev: any) → void
| arg | type | description |
|---|---|---|
| self | any | |
| name | string | |
| ev | any |
_emit(self: any, name: string, ev: any) → void
| arg | type | description |
|---|---|---|
| self | any | |
| name | string | |
| ev | any |
_find(self: any, id: any) → any
| arg | type | description |
|---|---|---|
| self | any | |
| id | any |
player(self: any, id: any) → any
A player's record (see state()), or nil.
| arg | type | description |
|---|---|---|
| self | any | |
| id | any |
_cap(self: any, h: number) → number
| arg | type | description |
|---|---|---|
| self | any | |
| h | number |
_holeEv(self: any, p: any, extra: any?) → any
| arg | type | description |
|---|---|---|
| self | any | |
| p | any | |
| extra | any? |
_addPlayer(self: any, id: any, info: any) → any
| arg | type | description |
|---|---|---|
| self | any | |
| id | any | |
| info | any |
_removePlayer(self: any, id: any) → void
| arg | type | description |
|---|---|---|
| self | any | |
| id | any |
_syncPeers(self: any) → void
| arg | type | description |
|---|---|---|
| self | any |
_start(self: any) → void
| arg | type | description |
|---|---|---|
| self | any |
_shot(self: any, p: any) → void
| arg | type | description |
|---|---|---|
| self | any | |
| p | any |
_penalty(self: any, p: any, n: number, reason: string) → void
| arg | type | description |
|---|---|---|
| self | any | |
| p | any | |
| n | number | |
| reason | string |
_finishHole(self: any, p: any, capped: boolean) → void
| arg | type | description |
|---|---|---|
| self | any | |
| p | any | |
| capped | boolean |
_scoreKit(self: any, p: any, stars: number) → void
| arg | type | description |
|---|---|---|
| self | any | |
| p | any | |
| stars | number |
_advanceReady(self: any, at: number?) → void
move every player whose wait is over to their next hole. With waitForAll the players who holed out on a hole move on together: once nobody is still playing that hole (or an earlier one), at the latest of their advance times, so everyone starts the next hole at the same moment.
| arg | type | description |
|---|---|---|
| self | any | |
| at | number? |
_checkFinished(self: any) → void
| arg | type | description |
|---|---|---|
| self | any |
_restart(self: any) → void
| arg | type | description |
|---|---|---|
| self | any |
_apply(self: any, op: string, a: any, _from: any?) → void
one entry point for every change, local or requested by another machine
| arg | type | description |
|---|---|---|
| self | any | |
| op | string | |
| a | any | |
| _from | any? |
_request(self: any, op: string, a: any) → void
| arg | type | description |
|---|---|---|
| self | any | |
| op | string | |
| a | any |
addPlayer(self: any, id: any, info: any?) → void
Add a player (id = a peer id or any value your game uses for the ball's `player`). info: { name, colour }. A player who left and comes back keeps their scores.
| arg | type | description |
|---|---|---|
| self | any | |
| id | any | |
| info | any? |
removePlayer(self: any, id: any) → void
A player leaves: their scores stay on the card, they no longer hold up waitForAll or the end of the round.
| arg | type | description |
|---|---|---|
| self | any | |
| id | any |
shot(self: any, id: any) → void
A stroke for a player on their current hole (games without course balls; course balls count on their own).
| arg | type | description |
|---|---|---|
| self | any | |
| id | any |
penalty(self: any, id: any, n: number?, reason: string?) → void
Penalty strokes for a player on their current hole. reason: "water", "outOfBounds" or your own.
| arg | type | description |
|---|---|---|
| self | any | |
| id | any | |
| n | number? | |
| reason | string? |
holed(self: any, id: any) → void
The player's ball is in the cup: finishes their current hole.
| arg | type | description |
|---|---|---|
| self | any | |
| id | any |
stopped(self: any, id: any) → void
The player's ball came to rest (finishes a hole that reached its cap).
| arg | type | description |
|---|---|---|
| self | any | |
| id | any |
start(self: any) → void
Start a round created with autoStart = false.
| arg | type | description |
|---|---|---|
| self | any |
restart(self: any) → void
Play the round again from hole 1 with the players still here.
| arg | type | description |
|---|---|---|
| self | any |
pars(self: any) → void
The pars of the round's holes, in order.
| arg | type | description |
|---|---|---|
| self | any |
ranking(self: any) → void
The ranking: the final one once the round is finished, else the standing now.
| arg | type | description |
|---|---|---|
| self | any |
scorecardPlayers(self: any) → void
Players shaped for puttCourse.scorecard: { { id, name, colour, strokes = { holes played } } }, so `Scorecard.render(round:scorecardPlayers(), round:pars(), style)` draws the card.
| arg | type | description |
|---|---|---|
| self | any |
destroy(self: any) → void
Stop the round: listeners, its synced entity (when this machine owns it).
| arg | type | description |
|---|---|---|
| self | any |
_listenCourse(self: any) → void
| arg | type | description |
|---|---|---|
| self | any |
route(op: string, extra: any?) → void
| arg | type | description |
|---|---|---|
| op | string | |
| extra | any? |
_holeHandle(self: any, hid: string) → any
| arg | type | description |
|---|---|---|
| self | any | |
| hid | string |
_placeBalls(self: any) → void
on every machine: put the balls it owns where the round wants them
| arg | type | description |
|---|---|---|
| self | any |
_tick(self: any, dt: number, now: number) → void
| arg | type | description |
|---|---|---|
| self | any | |
| dt | number | |
| now | number |
_step(self: any, now: number?) → void
Tests and tools: run one round tick now (what the course runtime does every frame).
| arg | type | description |
|---|---|---|
| self | any | |
| now | number? |
Multi-hole stroke-play rounds for mini golf: strokes, penalties, par cap, stars, next tee, waitForAll, join/leave, restart, ranking; one synced authority in multiplayer.Sub-parts
Everything contained inside this part. Assets are composite children (clickable cards). Files are leaf payloads. Expand any row to view its source.
Showing up to 3 levels deep. Open a part to see what it holds further down.
Problems
Everything affecting this asset right now: its own problems, anything wrong inside it, and problems on its direct dependencies.
agent_score is exposed.+ quality × 0.35
+ performance × 0.25
± compat factor
Usability ratings
Did the part work as advertised when consumers tried to drop it in. Separate from upvotes: those are taste; this is "did it function".
Scoped to this part · feeds back into the world's score.