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): IntReference
Section titled “Reference”useSkill(skill)
Section titled “useSkill(skill)” const attack = useSkill(Skills.ATTACK); const strength = useSkill(Skills.STRENGTH); const defence = useSkill(Skills.DEFENCE);Parameters
Section titled “Parameters”-
skill: ASkills.*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>;
Returns
Section titled “Returns”The level the player has right now, as an Int.
Caveats
Section titled “Caveats”- 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 withuseServerState, which does the same thing.
const Level = ({ skill }: { skill: Skill }): Component => { const level = useSkill(skill); // which skill? nothing can sayShowing a level
Section titled “Showing a level” <SkillTile icon={SkillIcons.get(Skills.STRENGTH)} level={strength} base={baseStrength} x={1} y={1 + TILE_H} /> <text x={32} y={4} w={15} h={12} text={`${level}`} font={Fonts.SMALL} align="center" shadow color={level > base ? Colors.GREEN : Colors.YELLOW} />Gating on a level
Section titled “Gating on a level”export const Spellbook = (): Component => { const magic = useSkill(Skills.MAGIC); <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.
Troubleshooting
Section titled “Troubleshooting”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.
A requirement passes while boosted
Section titled “A requirement passes while boosted”Switch to useSkillBase.