param
param, paramText and paramSprite read a parameter — a value the
game’s data attaches to an item, an NPC or a world object — by naming the
parameter’s reference. param answers a number, paramText a string,
paramSprite a sprite.
param(config: Item | Npc | WorldObject, ref: ParamRef): IntparamText(config: Item | Npc | WorldObject, ref: ParamRef<'string'>): StringparamSprite(config: Item | Npc | WorldObject, ref: ParamRef): SpriteReference
Section titled “Reference”param(config, ref)
Section titled “param(config, ref)”const SpellCard = ({ spell, magic, y }: { spell: Item; magic: Int; y: Int }): Component => { const needs: Int = param(spell, SpellParams.LEVEL);Parameters
Section titled “Parameters”config: The thing that carries the parameter, typed as what it is — anItem, anNpcor aWorldObject. A bare number is refused (TS2E120).ref: AParams.*reference, or a bare id for a parameter nobody has named yet —param(item, 1465).
Returns
Section titled “Returns”The value, as an Int — unless the reference says what the parameter holds, in
which case it reads back as that.
paramText(config, ref)
Section titled “paramText(config, ref)” <text x={34} y={5} w={{ fill: 40 }} h={14} text={paramText(spell, SpellParams.NAME)}Parameters
Section titled “Parameters”ref: A reference typed'string'. An int-typed reference is refused by the type checker (TS2345).
Returns
Section titled “Returns”A String.
paramSprite(config, ref)
Section titled “paramSprite(config, ref)” <sprite x={6} y="center" w={20} h={20} sprite={paramSprite(spell, SpellParams.ICON)} />Returns
Section titled “Returns”A Sprite. param already answers a Sprite for a reference typed
'sprite'; this is for one that has no reference to be typed.
Caveats
Section titled “Caveats”-
A read is total. Every parameter carries a default, and a config that does not set it reads that default back. There is no miss to handle, and no
null. -
The type is a claim the reference makes. Generated parameters are typed as numbers; declare an alias to type one:
src/refs-reference-surface.ts2 export declare const SpellParams: {/** `param_601` — the spell's name, as the spellbook spells it. */readonly NAME: ParamRef<601, 'string'>;/** `param_602` — the one-line description under it. */readonly DESCRIPTION: ParamRef<602, 'string'>;/** `param_597` — the spellbook icon, lit. */readonly ICON: ParamRef<597, 'sprite'>;/** `param_604` — the Magic level the spell needs. */readonly LEVEL: typeof GameParams.SPELL_LEVELREQ;}; -
A named parameter is usually a field.
item.levelrequire!reads the same parameterparam(item, AxeParams.LEVEL_REQUIRED)does — Reading game data.paramis for a parameter that has no field: one nobody has named, or one on a config the render only holds as a value. -
A row’s parameter is read through the row —
row.int(ref),row.text(ref),row.sprite(ref); of the item in a container slot, through the container —inv.param(slot, ref)and its pair.
const needs: Int = param(1359, 23); // 1359 is a number, not an Item return <text w="fill" h={16} text={paramText(spell, Params.SPELL_NAME)} font={Fonts.PLAIN} color={Colors.AMBER} />; // typed as an intDrawing a card from a config’s parameters
Section titled “Drawing a card from a config’s parameters”const SpellCard = ({ spell, magic, y }: { spell: Item; magic: Int; y: Int }): Component => { const needs: Int = param(spell, SpellParams.LEVEL);
return ( <layer x={0} y={y} w="fill" h={CARD_H}> <SunkenBox> <sprite x={6} y="center" w={20} h={20} sprite={paramSprite(spell, SpellParams.ICON)} /> <text x={34} y={5} w={{ fill: 40 }} h={14} text={paramText(spell, SpellParams.NAME)} font={Fonts.PLAIN} valign="middle" shadow color={magic >= needs ? Colors.YELLOW : Colors.DIM} /> <text x={34} y={22} w={{ fill: 40 }} h={14} text={paramText(spell, SpellParams.DESCRIPTION)} font={Fonts.SMALL} valign="middle" shadow color={Colors.DIM} /> <text x="right" y={5} w={60} h={14} text={`Level ${needs}`} font={Fonts.SMALL} align="right" valign="middle" shadow color={magic >= needs ? Colors.GREEN : Colors.RED} /> </SunkenBox> </layer> );};Reading one parameter by name
Section titled “Reading one parameter by name” const rune: Item = Axes.RUNE; const runeNeeds: Int = param(rune, AxeParams.LEVEL_REQUIRED);Troubleshooting
Section titled “Troubleshooting”param reads a parameter off an item, an NPC or an object
Section titled “param reads a parameter off an item, an NPC or an object”The first argument is a bare number. Type it: const item: Item = …, or take
it as an Item prop.
paramText will not take my reference
Section titled “paramText will not take my reference”The reference is typed as a number. Declare an alias typed 'string' for it,
as SpellParams.NAME is, and read through that.
The value is 0 for every item
Section titled “The value is 0 for every item”The parameter is not on those items, and 0 is its default. Check the id.
A parameter’s reference type, and how a named one carries what it holds, is under Types.