Skip to content

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): Int
paramText(config: Item | Npc | WorldObject, ref: ParamRef<'string'>): String
paramSprite(config: Item | Npc | WorldObject, ref: ParamRef): Sprite
src/reference-param.ts2
const SpellCard = ({ spell, magic, y }: { spell: Item; magic: Int; y: Int }): Component => {
const needs: Int = param(spell, SpellParams.LEVEL);
  • config: The thing that carries the parameter, typed as what it is — an Item, an Npc or a WorldObject. A bare number is refused (TS2E120).
  • ref: A Params.* reference, or a bare id for a parameter nobody has named yet — param(item, 1465).

The value, as an Int — unless the reference says what the parameter holds, in which case it reads back as that.

src/reference-param.ts2
<text x={34} y={5} w={{ fill: 40 }} h={14} text={paramText(spell, SpellParams.NAME)}
  • ref: A reference typed 'string'. An int-typed reference is refused by the type checker (TS2345).

A String.

src/reference-param.ts2
<sprite x={6} y="center" w={20} h={20} sprite={paramSprite(spell, SpellParams.ICON)} />

A Sprite. param already answers a Sprite for a reference typed 'sprite'; this is for one that has no reference to be typed.

  • 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 parameter param(item, AxeParams.LEVEL_REQUIRED) does — Reading game data. param is 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.

refused/param.ts2
const needs: Int = param(1359, 23); // 1359 is a number, not an Item
refused/param-text.ts2
return <text w="fill" h={16} text={paramText(spell, Params.SPELL_NAME)} font={Fonts.PLAIN}
color={Colors.AMBER} />; // typed as an int

Drawing a card from a config’s parameters

Section titled “Drawing a card from a config’s parameters”
src/reference-param.ts2
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>
);
};
src/game-data.ts2
const rune: Item = Axes.RUNE;
const runeNeeds: Int = param(rune, AxeParams.LEVEL_REQUIRED);

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.

The reference is typed as a number. Declare an alias typed 'string' for it, as SpellParams.NAME is, and read through that.

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.