Search the docs

Find a guide, global, type or member

Ledger

A per-player balance of one currency, saved in the data store as each change is made. Amounts given to canAfford, earn and spend must be zero or more; a negative one raises.

Fields

ledger.name: string#

The name it was opened with.

Methods

ledger:balance(player: PlayerRef) -> Bignum#

The player's balance; the opening balance if they have never had one.

ledger:canAfford(player: PlayerRef, amount: BigLike) -> boolean#

Whether the balance is at least amount.

ledger:earn(player: PlayerRef, amount: BigLike) -> Bignum#

Adds amount and returns the new balance.

ledger:spend(player: PlayerRef, amount: BigLike) -> boolean#

Takes amount if the player can afford it and returns true. false leaves the balance alone

ledger:set(player: PlayerRef, amount: BigLike)#

Sets the balance outright; any whole value, negative included.

ledger:reset(player: PlayerRef)#

Sets the balance back to what ledger.open gave as the start. back to the opening balance

ledger:onChange(fn: (player: PlayerRef, now: Bignum, before: Bignum) -> ())#

Calls fn(player, now, before) after a balance changes; setting the same value is no change.