Skip to content

useSkill

useSkill is a hook that reads a skill’s current level — boosts and drains included — and makes the component follow it. Its pair, useSkillBase, reads the level underneath.

useSkill(skill: SkillRef): Int
src/skills.ts2
const attack = useSkill(Skills.ATTACK);
const strength = useSkill(Skills.STRENGTH);
const defence = useSkill(Skills.DEFENCE);
  • skill: A Skills.* reference, named at the call. A project declares them once:

    src/refs.ts2
    export declare const Skills: {
    readonly ATTACK: SkillRef<0>;
    readonly SAILING: SkillRef<23>;
    readonly DEFENCE: SkillRef<1>;
    readonly STRENGTH: SkillRef<2>;

The level the player has right now, as an Int.

  • The reference is named at the call. A skill arriving as a prop, chosen by a conditional or taken from an array is refused (TS2E123). Pass the level down instead — the tile below takes two plain numbers.
  • Read-only, like every game value.
  • A Skills.* reference also works with useServerState, which does the same thing.
refused/use-skill.ts2
const Level = ({ skill }: { skill: Skill }): Component => {
const level = useSkill(skill); // which skill? nothing can say
src/skills.ts2
<SkillTile icon={SkillIcons.get(Skills.STRENGTH)} level={strength} base={baseStrength} x={1} y={1 + TILE_H} />
src/skills.ts2
<text x={32} y={4} w={15} h={12} text={`${level}`} font={Fonts.SMALL}
align="center" shadow
color={level > base ? Colors.GREEN : Colors.YELLOW} />
src/reference-param.ts2
export const Spellbook = (): Component => {
const magic = useSkill(Skills.MAGIC);
src/reference-param.ts2
<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} />

For a requirement that a potion should not unlock, read the base level instead — useSkillBase.

The level does not change when I drink a potion

Section titled “The level does not change when I drink a potion”

Check you are using useSkill rather than useSkillBase — the base level is deliberately unaffected by boosts.

Switch to useSkillBase.