โ ๐ Lua World
๐ Health Potion
You can practise without a player, but pick a player to score points!
๐ The mission
Today you unlock
Cap a value
Game stats often have a maximum. First add the potion to the health, then stop the result at 100 so overhealing never goes too high.
๐ก Hint ladder
- Add them first: local newHealth = health + potion
- if newHealth > 100 then return 100 end
- math.min(health + potion, 100) does it in one line!
๐งช Coach checks
- โฏ normal heal 50+30
- โฏ caps at 100
- โฏ exactly 100 stays
- โฏ tiny heal
Live coach
Getting ready
โโโ
๐ฌ math.min picks the smaller of two numbers โ great for capping things.
print(math.min(80, 100)) -- 80 (80 is smaller) print(math.min(120, 100)) -- 100 (never above the cap!) function addCoins(coins, found) return coins + found end print(addCoins(50, 30)) -- 80
๐ It printed:
Nice โ you saw it work!
๐ Output
๐งฉ Gaps filled! Ready to write it all yourself?