range3
Number ranges with a number inside them: min, current and max, like a health bar. A range can be changed, like a table.
range3.newfunction
range3.new(min: number, current: number, max: number): range3A number range with a number inside it, like a health bar: local health = range3.new(0, 100, 100), then health.current -= 20. current always stays from min to max.
| Value | Type | |
|---|---|---|
min | number | |
current | number | |
max | number |
Gives: range3.
range3.minfunction
r.min: numberIts smallest number. Set past max, max moves with it; current stays inside.
range3.currentfunction
r.current: numberThe number inside it. Set outside, it stops at min or max.
range3.maxfunction
r.max: numberIts biggest number. Set below min, min moves with it; current stays inside.
range3.fractionfunction
r.fraction: numberHow far current is from min to max, from 0 to 1: health.fraction * 4 is how wide a 4-tile health bar is. Set it to put current there.
range3:lerpfunction
r:lerp(t: number): numberThe number t of the way from min (t = 0) to max (t = 1), as math.lerp.
| Value | Type | |
|---|---|---|
t | number |
Gives: number.
range3:clampfunction
r:clamp(x: number): numberx kept inside the range.
| Value | Type | |
|---|---|---|
x | number |
Gives: number.
range3:containsfunction
r:contains(x: number): booleanIs x inside the range (min and max count)?
| Value | Type | |
|---|---|---|
x | number |
Gives: boolean.
range3:randomfunction
r:random(): numberA random number inside the range.
Gives: number.
range3.changedfunction
r.changed: eventAn event that happens when one of its numbers changes: health.changed:connect(function() bar.width = health.fraction * 4 end).