2026-05-25 07:55 UTC
That'd be a class in most (OOP) languages
class Ranged {
value: Int
min: Int
max: Int
fn init(min: Int, value: Int, max: Int) {
self.min = min
self.max = max
self.value = clamp(min, value, max)
}
fn set(new: Int) {
self.value = clamp(self.min, new, self.max)
}
}
let health = new Ranged(0, 100, 100)
health.set(health - damage)
// damage is 120 from some far away code
// Ranged doesn't let it become -20
Replies (0)
No replies.