Reconsider the Deprecation of ConstrainedValue Objects

As a Roblox developer, I feel that the ConstrainedValue objects still have purpose, even with the addition of math.clamp into the math library.

Although the IntConstrainedValue and DoubleConstrainedValue objects were deprecated long ago, they still had one benefit over the math.clamp function - simplified communication between scripts. The reason why I still use ConstrinedValue objects for some of my work is not because of the Value property, but because of the MinValue and MaxValue properties. These properties allowed for multiple scripts to communicate with the upper and lower bounds of a constrained value without having to create two additional IntValue/DoubleValue objects, or program the behaviour of the upper and lower bounds into every script that interacts with the value.

Let’s say I have a health bar, and I want to program its value to read in percent. Assuming the maximum health does not stay constant - perhaps due to powerups, having 100 health does not always mean you’re at 100%. Programming the behaviour of the powerups into the health bar code is out of the question, since you can have an unlimited amount of powerups. The only simple way to get around this is to have an additional IntValue/DoubleValue for maximum health that the powerups will modify directly.

This would result in something like

return HealthBar.Health.Value / HealthBar.MaxHealth.Value

Whereas if we had a single ConstrainedValue, we’d have something like this

return HealthBar.Health.Value / HealthBar.Health.MaxValue

I mean it’s not that much of a difference right, plus we’d only need one additional IntValue/DoubleValue object for the maximum health, right?

True, but this gets exponentially more complex with the more constrained values you have. For example, if we have 4 constrained values in which both the upper and lower bounds weren’t constant - due to some external script. There’d have to be 2 additional IntValue/DoubleValue objects for each value, resulting in 12 total objects, rather than 4 with ConstrainedValues. Also, those 12 values will also need to adapt some sort of nomenclature or way to differentiate which minimum and maximum values belong to which constrained value.

Overall, the IntConstrainedValue and DoubleConstrainedValue objects served as a simplistic (yet versatile) way to constrain values, as well as allow external scripts to be aware of the bounds of said constraint. They allowed for developers to elegantly organize values without adding unnecessary code or keeping unnecessary objects in memory. I choose to bring this up now because as time progresses, the possibility of their complete removal becomes greater. Finally, I just urge for Roblox to reconsider the deprecation of these objects.

Thanks for reading :grin:

6 Likes