Summit Sprint: 3D Platformer Kit with a Playable Forest Course
- ..
- .metadata145 B
- README.md1.8 KB
- giveBack.module
- package.yaml627 B
README.md
pickupsGiveBack
Give one player back the per-player pickups they took. pickupsKit's mode = "perPlayer" pickups let every player take their own copy of a coin; each pickup remembers who took it. pickupsKit has no call to undo that for one player, which a level restart needs: Retry should give you your coins back without touching anyone else's. This part is that call.
local GiveBack = require("pickupsGiveBack.giveBack")
GiveBack.listen() -- once on every peer (e.g. in a component's start)
GiveBack.giveBack(myAvatar, "coins") -- every "coins" pickup is takeable by me again
GiveBack.giveBack(myAvatar, "coins", true) -- ...and my coins counter goes back to 0
| call | |
|---|---|
giveBack(player, counter, resetCount?) | player is an avatar entity, a peer number or a pickupsKit ledger key. Clears that player's claim on every per-player pickup whose counter matches; resetCount also sets their counter to 0. Returns how many this peer gave back at once. |
listen() | Start answering give-back requests from other peers. Idempotent; giveBack calls it too. |
applyHere(key, counter) | The local half: clears key on the pickups this peer owns. |
Multiplayer
A pickup's synced taken map is written by the peer that owns the pickup. giveBack applies the change to the pickups this peer owns and sends it on the pickupsGiveBack:v1 channel; every peer that has called listen() applies it to its own. Each player's claims are separate, so giving one player their coins back never returns anyone else's.
Known limits
- Every peer must have required the module and called
listen()(a component that uses it does this on start); a peer that never did keeps its pickups' claims.