Class 'ValueContainer'

Would be great if there would be a related class of BoolValue, NumberValue, ObjectValue, IntValue, etc.

Example:

if workspace.BoolValue:IsA('ValueContainer') then
     print('This is an object of class \'ValueContainer!\'')
end

Currently, the Value instances are all over the places.

Why not have them recognized in one orderly class?

19 Likes

Support.

Also for future reference you should say why it would be great, why it isn’t great now, etc.

It’s already pretty simple!

if workspace.BoolValue.ClassName:sub(-5) == "Value" then
  print('This is an object of class \'ValueContainer!\'')
end
10 Likes

I did not know string.sub could do that with negative parameters.
I’ve been doing
s:sub(s:len() - 5, s:len())
all this time

4 Likes

Well, you could do that. But it can be a bit longer to write, but its also as I requested Class 'ValueContainer' to just organize the Value instances in general. It seems logical for all Value instances to have a related class.

3 Likes

Wait do you mean like have all Values should inherit an abstract class? Similar to how all Gui objects are “GuiBase” and all Parts are “BasePart” ? Because I would totally support this.

2 Likes

Having it tie into IsA would be much nicer than doing object.ClassName:find(“Value”).

4 Likes

I do not support this for the following reason. Odds are when you’re going to use this, you’ll need it to be a specific value type, and not just any value, and you could just do IsA(“StringValue”).

ValueContainer

  • StringValue
  • BoolValue
  • IntValue

obj:IsA("ValueContainer") or obj.ClassName == "StringValue" like with any other object.

If the intent is to make these a single class, we would have to deprecate existing value objects to prevent old games from breaking, and new scripts could just read the ValueType property/etc of the new, singular class.

What’s the use case for ValueContainer? Every value is different and has different properties so it doesn’t really make sense.

Currently with ROBLOX’s infrastructure the value objects are disorganized. Look in the API. You’ll see what I mean.

Yeah, sure, but they aren’t all the same and don’t serve the same purpose. I get what you’re saying, “they’re all values” but they are different and shouldn’t be clumped together like other instances that are the same

They are all the same and all save the same purpose (store a value). They all have a Value property and a modified Changed event that fires when only Value changes (not name/etc). Their only difference is the Value property’s type. They’re more similar than something such as the subtypes of Constraint.

@woot3
Your code is actually a bit shorter than when this exact thread was made in 2015 and you suggested the same thing haha

This has been suggested a lot if you Search “ValueObject” on the forums

1 Like

I should of known there were threads before I posted this. Whoops.

(I actually did, but the search did not bring me relevant results \_(:P)_/)