Condense all value objects into one generic ValueObject

The downsides to creating a new object for each data type are that:

[ul]
[li]You have to create a new object every time you create a DataType (or should at least)[/li]
[li]Unable to use objects to store values for data types not represented with value objects (i.e. Vector2, UDim2, etc)[/li]
[li]Advanced Objects is spammed with lots of value objects since there are so many data types[/li]
[li]API bloat[/li]
[li]No way to check if something is a value object with :IsA(“ValueObject”) since all of them inherit directly from instance – you’d have to do .ClassName == “IntValue” or .ClassName == “NumberValue” or .ClassName" == “Color3Value”… etc.[/li]
[/ul]

If value objects are condensed into a single object with a “Type” property to set the data type it holds, all of those issues are resolved. You’re free to create a value object of any type that exists as soon as a new data type is created instead of hoping that a value object for that data type is eventually added, there will be only one object in the advanced objects window for value objects instead of 10, no need to create even more objects whenever new data types are added, bloating the API, and you’re able to check if something is a value object with .ClassName == “ValueObject”.

IntConstrainedValue and DoubleConstrainedValue should not be condensed into the ValueObject since they’re special and have min and max values that normal object values do not. However, ValueObject, IntConstrainedValue, and DoubleConstrainedValue should all inherit from a superclass “ValueObjects” (better name pls) so that a value object can be discerned with :IsA(“ValueObjects”).

1 Like
if object.className:match("Object") then
if object.className:match("Object") then

It’s a good workaround, but it’s still a workaround. :IsA() was created for this very purpose, but we’re not able to use it in this case. It’s a weakness of the API that if fixed would be nice.

Super necrobump.

This is something I still want. For scripters like me who are starting out and have weird setups, it’s nice to be able to collect values under a single class without having to do Object:IsA("IntValue") or Object:IsA("WhateverValue") or whatever repeatedly.

Right now, as a workaround, I’m using something that @Rerumu posted on a duplicate thread.

image

(In case anyone’s wondering why I’m using values in ServerStorage for data and not tables, it’s because the other scripters on the team need to be able to read my code and work with things easily, otherwise it’s not going to work out for them.)

One value superclass will probably save the lives of a lot of people. It’d also be neat to have.

Read the replies to this recent thread about the same issue: Please merge all the values into one Class! - #10 by TheEldritchDreamer
A superclass for the value objects is coming soon (within a couple weeks).

1 Like