According to a quick test Attributes are about 13% averagely faster than ValueObjects(Tested using String Value Object and String Attribute) according to test done by using 3 value objects and 3 attributes of which all there values are set randomly between 1 and 90 using math.random.
However it seems number value objects are alot faster than number attributes by 47%. Im not sure why but i’ve tested multiple times again following the same 3 rule 3 rule method.
If a part’s physics is being manipulated by the client will the attributes also replicate from client to server? For instance, the player’s character is almost always being controlled by the client. If an attribute is added to the Head part will it replicate all changes and additions to the server?
You can replicate this by waiting for the attribute changed event:
local attribute = instance:GetAttribute("Attribute")
if not attribute then
instance:GetAttributeChangedSignal("Attribute"):Wait()
attribute = instance:GetAttribute("Attribute")
end
We are unlikely to add a built-in method for this as nil is still a meaningful value. In that sense, how do you wait for nil?
How will attributes work with Parallel Lua? Will we be able to access them from other Actors or VMs? Is this a viable replacement for relying on modules returning the same value every time?
I’ve been using attributes while working on my combat system, and it’s more convenient than I anticipated.
it’d be cool if
Scripts could create private/read-only attributes
Arrays were supported
Object values were supported
The Properties window differentiated attributes so it’s clear that they’re not indexable.
I originally thought we could just do Object.AttributeName = 123. The documentation is clear enough, but it might confuse some kids. Better yet, maybe just make them indexable? Idk, could be another reason to have a method that lists the indexable properties of an object.
We also considered this and decided it wasn’t a great idea either. Unless you cache the value of ‘Attributes’ you’ll always be doing two index operations .Attributes and .MyAttribute. Performance wasn’t great as you can imagine, and neither was expecting developers to cache the value.
There’s still some weird semantics with mutability too:
-- this is fine
instance.Attributes.MyAttribute = Vector3.new(0, 0, 0)
-- this is not
instance.Attributes.MyAttribute.X = 5
Overall we concluded explicit getters and setters were ideal, and if developers wanted something else then they could always write a helper that used the same methods underneath.
I have one suggestion in regards to attribute value options. I think it would be handy to include “Int” as one of the data types, even though we already have the “number” value for this. Reasons for this is because:
Can stop decimals from being added to an attribute that is only compatible with Int. A user may accidentally put a decimal and might cause issues in scripts (such as sound id)
For free models using attributes as a way to configure stuff, users may attempt to put in number values as an attribute, which may cause scripts to break. This could be fixed by round up in scripts, but users may still think that entering a float number is okay as the attribute does not force whole number
(While “IntObject” does force whole number)
You already have an “IntObject” and a “NumberObject”. So why not also have “Int” Value as an attribute, which is a standard data type in most programming languages.