โ ๐ Lua World
๐ Damage Calculator
You can practise without a player, but pick a player to score points!
๐ The mission
Today you unlock
Functions return answers
A function is a tiny machine: it receives inputs, works something out, then returns one answer for the tests to check.
๐ก Hint ladder
- Subtract first, then check if it went below zero.
- math.max(attack - defense, 0) does it in one line.
๐งช Coach checks
- โฏ normal hit 10 vs 3
- โฏ blocked completely
- โฏ exactly blocked
- โฏ no armour
Live coach
Getting ready
โโโ
๐ฌ math.max picks the BIGGER of two numbers โ handy to stop things going below zero.
print(math.max(7, 0)) -- 7 print(math.max(-4, 0)) -- 0 (never below zero!) function spend(coins, price) return math.max(coins - price, 0) end print(spend(10, 3)) -- 7 print(spend(5, 9)) -- 0
๐ It printed:
Nice โ you saw it work!
๐ Output
๐งฉ Gaps filled! Ready to write it all yourself?