economy
The one interface a game uses for economyKit: `local Economy = require("economyKit.economy")`. It sets the economy up (which currencies, incomes and sinks are on, wallet display, shop screen, look), defines currencies, price lists, shops, incomes and sinks from code, reads the lo…
economy (economyKit)
The one interface a game uses for economyKit: local Economy = require("economyKit.economy"). It sets the economy up (which currencies, incomes and sinks are on, wallet display, shop screen, look), defines currencies, price lists, shops, incomes and sinks from code, reads the local player's wallet, sends buy, sell, spend, charge, grant, wave and trade requests to the bank and reports the answers as events, opens and closes shop screens, and places shopkeepers and coins. It chooses which machine runs the bank (the lowest peer) and passes messages between players and the bank. See the package README for every call.
Interface
What this asset declares: the schema it conforms to, what it exposes, and the rendered structured payload.
conforms to
zero/source-extract/v2strict
copy(v: any) → any
| arg | type | description |
|---|---|---|
| v | any |
now( ) → number
bump( ) → void
_rev( ) → number return S
inPlay( ) → boolean
online( ) → boolean
myPeer( ) → number
cfg( ) → any
list(v: any) → void
| arg | type | description |
|---|---|---|
| v | any |
setup(opts: any?) → any
Set the economy up. Every machine calls it with the same options (a scene's onLoad). opts: currencies (kit sample currencies to switch on, default { "coins" }), income, sinks (kit sample incomes / sinks to switch on), wallet (one style or a list: corner, panel, popup, minimal), screen (force every shop into one screen style), look (menusKit look), ns (save namespace), clientGrants ({ [reason] = { max, perMinute } } grants player machines may ask for), clientWaves, tradeFees (sink ids), npcTraders, save (copy wallets into saveKit), labels (caption each wallet display), toasts, insets.
| arg | type | description |
|---|---|---|
| opts | any? |
config( ) → any return copy
configure(opts: any) → void
Change some settings without starting over (setup's options, merged in): Economy.configure({ look = "pixel" }).
| arg | type | description |
|---|---|---|
| opts | any |
setWallet(styles: any) → void
Show one wallet style or several at once: "corner", "panel", "popup", "minimal" (or a list).
| arg | type | description |
|---|---|---|
| styles | any |
walletStyles( ) → void
setScreen(style: string?) → void
Force every shop into one screen style ("grid", "vendor", "vending", "quickBuy", "upgradeTree", "trade"), or nil to let each shop use its own.
| arg | type | description |
|---|---|---|
| style | string? |
setLook(look: string) → void
The menusKit look shops use when a shop does not name its own.
| arg | type | description |
|---|---|---|
| look | string |
setInsets(ins: any) → void
Keep the kit's screens clear of the game's own HUD: { left, top, right, bottom } in UI points.
| arg | type | description |
|---|---|---|
| ins | any |
define(kind: string, raw: any) → any
Add or replace a definition from code: kind is currency, priceList, shop, income or sink.
| arg | type | description |
|---|---|---|
| kind | string | |
| raw | any |
defineCurrency(raw: any) → any return M
| arg | type | description |
|---|---|---|
| raw | any |
definePriceList(raw: any) → any return M
| arg | type | description |
|---|---|---|
| raw | any |
defineShop(raw: any) → any return M
| arg | type | description |
|---|---|---|
| raw | any |
defineIncome(raw: any) → any return M
| arg | type | description |
|---|---|---|
| raw | any |
defineSink(raw: any) → any return M
| arg | type | description |
|---|---|---|
| raw | any |
reload( ) → number local n
currencies( ) → void
currency(id: string) → any
| arg | type | description |
|---|---|---|
| id | string |
shop(id: string) → any
| arg | type | description |
|---|---|---|
| id | string |
shops( ) → void
priceList(id: string) → any
| arg | type | description |
|---|---|---|
| id | string |
on(event: string, fn: (any) → void
Listen to an event (see Economy.EVENTS; "bank.<event>" hears the bank's own events on the bank's machine). Returns a function that stops listening.
| arg | type | description |
|---|---|---|
| event | string | |
| fn | (any |
emit(event: string, info: any) → void
| arg | type | description |
|---|---|---|
| event | string | |
| info | any |
text(reason: any) → string return Text
A refusal reason ({ code, values }) as text in the player's language.
| arg | type | description |
|---|---|---|
| reason | any |
field(obj: any, name: string) → any
| arg | type | description |
|---|---|---|
| obj | any | |
| name | string |
playerList( ) → void
ownerOf(e: any) → number
| arg | type | description |
|---|---|---|
| e | any |
peerOfRecord(p: any) → number
| arg | type | description |
|---|---|---|
| p | any |
keyFor(uid: string, peer: number, records: { any }) → string
One account signed in on two machines is two players: the lowest peer keeps "u:<id>", the next is "u:<id>#2" (see Known limits: #14448).
| arg | type | description |
|---|---|---|
| uid | string | |
| peer | number | |
| records | { any } |
localUserId( ) → string
_keyOf(peer: number) → string
The account a machine plays as, as the bank sees it: "u:<userId>" (persisted) or nil while unknown.
| arg | type | description |
|---|---|---|
| peer | number |
_nameOf(peer: number) → string
| arg | type | description |
|---|---|---|
| peer | number |
avatarOfPeer(peer: number) → any
| arg | type | description |
|---|---|---|
| peer | number |
_posOf(peer: number) → any
| arg | type | description |
|---|---|---|
| peer | number |
peerList( ) → void
bankPeer( ) → number
The machine that runs the bank: the lowest peer in the room (this machine when alone).
inventory( ) → any
The inventoryKit this economy runs on (its `inventoryKit.inventory` module). A game or kit that installed economyKit reaches inventoryKit through here, so it talks to the same bag economyKit fills and never needs inventoryKit as a dependency of its own.
isBank( ) → boolean
Whether this machine runs the bank.
inventoryCount(peer: number, item: string) → number
| arg | type | description |
|---|---|---|
| peer | number | |
| item | string |
inventoryRoom(peer: number, item: string, n: number) → boolean
| arg | type | description |
|---|---|---|
| peer | number | |
| item | string | |
| n | number |
storeNs( ) → string
the namespace wallets are kept under, scoped to this world: a store an engine carried over from another world (seen after switching worlds in one session) never hands a player that world's money
bankEnv( ) → any
send(peer: number, msg: any) → void
| arg | type | description |
|---|---|---|
| peer | number | |
| msg | any |
hasItem(item: string) → void
| arg | type | description |
|---|---|---|
| item | string |
emit(event: string, info: any) → void
| arg | type | description |
|---|---|---|
| event | string | |
| info | any |
becomeBank( ) → void
stopBank( ) → void
deliver(peer: number, msg: any) → void
send one message to a machine's client side (the bank answering), or to the bank
| arg | type | description |
|---|---|---|
| peer | number | |
| msg | any |
toBank(msg: any) → void
| arg | type | description |
|---|---|---|
| msg | any |
route(from: number, env: any) → void
| arg | type | description |
|---|---|---|
| from | number | |
| env | any |
listen( ) → void
processInbox( ) → void
request(op: string, body: any, info: any?, cb: ((any) → void
| arg | type | description |
|---|---|---|
| op | string | |
| body | any | |
| info | any? | |
| cb | ((any |
textOf(code: string?, values: any?) → string
| arg | type | description |
|---|---|---|
| code | string? | |
| values | any? |
finish(id: string, res: any) → void
| arg | type | description |
|---|---|---|
| id | string | |
| res | any |
giveItems(items: any) → void
| arg | type | description |
|---|---|---|
| items | any |
clientReceive(msg: any) → void
| arg | type | description |
|---|---|---|
| msg | any |
balance(cur: string) → number
The local player's balance of one currency (0 while unknown).
| arg | type | description |
|---|---|---|
| cur | string |
balances( ) → void
Every switched-on currency's balance for the local player: { [currency] = n }.
wallet( ) → any
A copy of the local player's wallet { b, rev, bought }, or nil before the bank has answered.
isReady( ) → boolean return S
Whether the bank has told this machine its wallet yet.
key( ) → string
The account key the bank keeps this player's wallet under ("u:<userId>").
canAfford(costs: { [string]: number }) → void
Can the local player pay these costs ({ [currency] = n })? Returns ok and the shortfalls { { currency, need, have, cost } }. Only a preview: the bank decides.
| arg | type | description |
|---|---|---|
| costs | { [string]: number } |
quote(shopId: string, item: string, n: number?) → any
How buying from a shop looks for the local player: { entry, cost, base, fees, affordable, short, limit, ok, owned } or nil.
| arg | type | description |
|---|---|---|
| shopId | string | |
| item | string | |
| n | number? |
buy(shopId: string, item: string, n: number?, cb: ((any) → void
Ask the bank to buy `n` (default 1) of an item from a shop. The bank checks the price list, stock, prerequisites, room in the bag and the wallet, then takes the money and the item lands in the inventory, or refuses with a reason. `cb(info)` runs with the answer. Returns the request id.
| arg | type | description |
|---|---|---|
| shopId | string | |
| item | string | |
| n | number? | |
| cb | ((any |
sell(shopId: string, item: string, n: number?, cb: ((any) → void
Ask the bank to buy `n` of an item back. The item leaves the bag first; the money arrives once the bank sees it gone.
| arg | type | description |
|---|---|---|
| shopId | string | |
| item | string | |
| n | number? | |
| cb | ((any |
spend(curOrCosts: any, amount: number?, reason: string?, cb: ((any) → void
Spend the local player's own money: spend("coins", 25, "revive") or spend({ coins = 25, gems = 1 }, nil, "reason").
| arg | type | description |
|---|---|---|
| curOrCosts | any | |
| amount | number? | |
| reason | string? | |
| cb | ((any |
charge(sinkId: string, cb: ((any) → void
Take a one-off charge defined as an economyKit.sink of kind "charge" (a revive, a fare).
| arg | type | description |
|---|---|---|
| sinkId | string | |
| cb | ((any |
keyOfTarget(target: any) → string
| arg | type | description |
|---|---|---|
| target | any |
grant(target: any, cur: string, amount: number, reason: string?, cb: ((any) → void
Give money (a negative amount takes it). On the bank's machine (host-side game code: a kill reward, a quest) it applies at once to `target` (nil = the local player, a peer id, a user id or an avatar). From a player's machine it is a request the bank grants only for reasons the game allowed in setup's clientGrants.
| arg | type | description |
|---|---|---|
| target | any | |
| cur | string | |
| amount | number | |
| reason | string? | |
| cb | ((any |
wave(n: number?, cb: ((any) → void
Start wave `n` (or the next one): every onWave income pays every player. Call it from the host's game code; a player's machine may only ask when setup allows clientWaves.
| arg | type | description |
|---|---|---|
| n | number? | |
| cb | ((any |
tradeWith(target: any, cb: ((any) → void
Invite another player to trade (a peer id), or "npc:tobi" to practise with the trading post's trader.
| arg | type | description |
|---|---|---|
| target | any | |
| cb | ((any |
trade( ) → any
tradeAnswer(accept: boolean, cb: ((any) → void
| arg | type | description |
|---|---|---|
| accept | boolean | |
| cb | ((any |
tradeOffer(offer: any, cb: ((any) → void
Set what the local player offers: { items = { [itemId] = n }, money = { [currency] = n } }. Both sides' "accept" resets.
| arg | type | description |
|---|---|---|
| offer | any | |
| cb | ((any |
tradeReady(ready: boolean?, cb: ((any) → void
| arg | type | description |
|---|---|---|
| ready | boolean? | |
| cb | ((any |
tradeCancel(cb: ((any) → void
| arg | type | description |
|---|---|---|
| cb | ((any |
_clearTrade( ) → void
tradePartners( ) → void
The players this machine could trade with: { { peer, name, key } }.
open(shopId: string, opts: any?) → boolean
Open a shop's screen for the local player. opts: screen (force a style), look, tab ("buy"/"sell"), silent.
| arg | type | description |
|---|---|---|
| shopId | string | |
| opts | any? |
close( ) → void
isOpen( ) → boolean return S
current( ) → any
_open( ) → any
_registerKeeper(id: string, info: any) → void
| arg | type | description |
|---|---|---|
| id | string | |
| info | any |
_unregisterKeeper(id: string) → void
| arg | type | description |
|---|---|---|
| id | string |
_keepers( ) → any return S
spawnShopkeeper(opts: any) → any
Place a shopkeeper (a local entity on this machine; call it on every machine, e.g. in onLoad). opts: kind (counter, machine, holo), shop, position, yaw (degrees), label (show the shop's name above it, default true), labelWidth (widest the name may be, metres, default 3; a long name shrinks to fit on one line), marker (the floating coin over its head, default true), name.
| arg | type | description |
|---|---|---|
| opts | any |
spawnCoin(pos: any, opts: any?) → any
Put a coin on the ground that pays the player who walks into it (the bank checks they are really there). Call it on every machine with the same id. opts: id, currency (default coins), amount (default 5), respawn (seconds, default 12).
| arg | type | description |
|---|---|---|
| pos | any | |
| opts | any? |
_coinTaken(id: string) → boolean
| arg | type | description |
|---|---|---|
| id | string |
_pickup(id: string) → void
| arg | type | description |
|---|---|---|
| id | string |
_popups( ) → void
_attach(id: string) → void
| arg | type | description |
|---|---|---|
| id | string |
_detach(id: string) → void
| arg | type | description |
|---|---|---|
| id | string |
_ensureHost( ) → void
Make sure this machine's local EconomyHost (UI, input, network) exists. Called by every API that needs it.
retryPending( ) → void
mirrorToSave(dt: number) → void
| arg | type | description |
|---|---|---|
| dt | number |
_tick(dt: number) → void
Run one frame (EconomyHost calls this): choose the bank, pass messages, retry, pay income, keep the saveKit copy.
| arg | type | description |
|---|---|---|
| dt | number |
_reset( ) → void
Forget everything this machine knows (tests; a new play session).
styleEntries(family: string) → void
| arg | type | description |
|---|---|---|
| family | string |
styles(family: string, query: any?) → void
The styles of one family ("screen", "icon", "wallet" or "keeper"), each as { id, name, label, tags }, optionally only those whose tags match: `Economy.styles("icon", { setting = "sci-fi" })`, or a bare word matched against every tag: `Economy.styles("screen", "gamepad")`.
| arg | type | description |
|---|---|---|
| family | string | |
| query | any? |
holds(values: any, want: string) → boolean
| arg | type | description |
|---|---|---|
| values | any | |
| want | string |
catalogue( ) → any
Everything the kit offers, as data. `screens`, `icons`, `wallets` and `keepers` are lists of { id, name, label, tags }, the tags saying each style's `style`, `genre` and `setting` (plus `input` for screens, `size` for wallets); `looks` are menusKit's looks; the rest are the ids of what the game has defined.
ids(kind: string, all: boolean?) → void
| arg | type | description |
|---|---|---|
| kind | string | |
| all | boolean? |
The public economyKit API: setup, data definitions, wallet reads, buy/sell/spend/grant/trade requests to the authoritative bank, events, shop screens, shopkeepers and coins.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.