Amounts
An amount is a number content names, such as a stat or a formula, that the engine works out when it reads it.
An amount is a number that content names and the engine works out when it reads it: a plain number, a stat, a kv key, a value, a count of entities, or a formula of them. Range bounds, a stat effect's by and to, a stat's min and max and a roll's target all take one, so "coins at least the rent" needs no code. Effects and conditions are data explains why content stays data.
In the showcase: examples/showcase/src/story/park.ts, whose skimming roll has a target in against.
import { amountOf, type Amount } from '@ifloom/engine'Amount
A number content names that the engine works out when it reads it. Every form is in Amount.
| Key | Meaning |
|---|---|
12 | The number as written. |
'coins' | The player's stat with that id. |
{ stat, of? } | A stat, the player's or with of an entity's, read as statValue reads it. |
{ kv, of? } | A key's number in a kv store, the player's or with of another's. A value that isn't a number counts as 0. |
{ value, with? } | A value by name, the game's own (game/…) or a plugin's, asked with with. Text that reads as a number counts as that number. |
{ count, where? } | The number of entities, counted as the count condition counts them. |
{ sum }, { product }, { min }, { max } | The sum, product, least or greatest of a list of amounts. |
{ scale, by } | An amount multiplied by the number by, so { scale: 'coins', by: -1 } is minus the player's coins. |
{ clamp, min?, max? } | An amount held between two numbers. |
of names the owner as it does in conditions: an EntityRef, '$' inside an each or a where, and 'storyline:<id>' or 'minigame' for a kv key. An amount that doesn't read as a finite number is 0, and so is an owner that isn't there.
The engine works an amount out each time it reads it: as an effect applies, as a condition is asked, or as a stat is held to its range. A choice's price reads its stat effect's amount in the state on screen.
These fields take an amount:
- The bounds of every
Range, in every condition that takes one, a call's own bounds included. - The
stateffect'sbyandto. - The
kveffect'sby, and each end of itsrandom. - The
receiveandreleaseeffects'by. - A roll's
plusandagainst. - A stat's
minandmax. - A plugin field the plugin declares to the checker as
{ amount }, such as an achievement's progress or a device app's badge.
This content caps energy at the player's fitness, and pays each member of staff their own wage:
import type { Content } from '@ifloom/engine'
export const week: Content = {
stats: [
{ id: 'fitness', label: 'Fitness', start: 40 },
{ id: 'energy', label: 'Energy', start: 30, max: { stat: 'fitness' } },
],
actions: [
{
id: 'payday',
label: 'Pay the staff',
effects: [{ each: 'staff', effects: [{ stat: 'coins', by: { scale: { stat: 'wage', of: '$' }, by: -1 } }] }],
},
],
}Functions
amountOf
Returns an amount worked out in a state, as the engine reads one. Its signature is in amountOf.
A plugin calls it for a field of its own that takes an amount, and declares the field to the content checker as { amount } in its references.
import { amountOf } from '@ifloom/engine'
amountOf(state, game, { stat: 'coins' }) // 12
amountOf(state, game, { sum: ['coins', { kv: 'tips' }] }) // 15
amountOf(state, game, { count: 'staff' }) // 2Checks
The content checker reads every amount content writes, and reports these problems:
| Problem | Cause |
|---|---|
unknown stat "gold" | The amount names a stat the game doesn't declare, or one declared on another owner. |
unknown storyline "nobody" | A { kv, of: 'storyline:…' } names a storyline the game doesn't declare. |
no game value named "game/nothing" | A { value } names a value nobody declares. |
an amount is a number, a stat id, a formula, { stat }, { kv }, { value } or { count }; this one is [3] | The amount has none of the shapes above. |
Caveats
- In a
kveffect,tostays aKvValueas written, since a string there is text and not a stat's id. Akveffect changes a key by an amount withby. - A stat's
maxorminthat comes back to the stat itself, such as a derived stat whose ceiling reads it, reads its default (100, or 0) while the engine works it out. - A
maxorminnaming a value nobody declares, such as one from a plugin the game no longer has, reads its default too.
Last updated on