Skip to main content

Code frameworks

Recipe: bound a number

Limit what a player can enter for a number.

Goal

Keep the maximum HP of a Keeper between 1 and 40.

The change

schemas/keeper.json
    "max_hp": {
      "label": "Maximum HP",
      "description": "How much damage a Keeper can take.",
      "defaultValue": 10,
      "min": 1,
      "max": 40
    }
  1. Lines 12-13 min and max bound the number. min must not exceed max.

A scenario or preset outside the bounds fails the check:

Parameter max_hp 99 is not between 1 and 40.

Test it

Test the edges: use the lowest and the highest value in a preset or a scenario.

Next