Edit: This thread is still being brought up so and at the time, clarification on the true desired goal was hazy so I thought i’d update the thread. The true goal here is to have access to a list of an Instance’s properties. Right now, people use API dumps to accomplish this, but having to use external sources is not really ideal especially in terms of maintainability.
Some use cases as specified in earlier discussions:
Currently, getting and setting properties can be a time consuming task. 2 additions and 1 change in the API would allow use to easily get and set a mass of properties with ease.
API Addition #1:
A :GetProperties() method. This method will put all of the property details in a single table and return it. You can then set this to a variable and use it, similar to :GetChildren()
Edit: The :GetProperty() method should also take optional parameters. This optional parameter will either get a specific property (or group of properties), a property categorization (Appearance, Data, Behavior etc) or it gets all of the properties if left blank.
Example:
local PropTable = Workspace.Part:GetProperties()
Returns Table with all properties
local PropTable = Workspace.Part:GetProperties(“Appearance”)
Returns table with properties under the appearance categorization as shown in the properties panel.
local PropTable = Workspace.Part:GetProperties(“BrickColor”,“Material”,“Name”)
Returns a table with the BrickColor, Material, and Name properties.
API Addition #2:
A :SetProperties(Table) method. This works together with the :GetProperties method. If the code behind the method can detect any correct values in the table and match it with the object’s properties then apply the changes to the part.
Example:
local PropTable = Workspace.Part:GetProperties()
Workspace.Part2:SetProperties(PropTable)
API Change #1:
This change adds a new parameter to Instance.new(), it will take a table as a 3rd parameter and basically do the same thing as the :SetProperties method. It will read the properties of the table and apply it to the newly instanced part. This is a good way for coders to setup their own default properties for their instanced part.
local NewPart = Instance.new(“Part”,Workspace,PropTable)
I think these additions will help improve the workflow for coders and overall make certain task that have to do with properties easier.
There may be a big question that comes up with “You can already do this yourself.”
While yes, you can, It’s just a very annoying thing to do. Nobody wants to set all of the parts individually or set all the parts themselves in a table. These API changes just saves time and makes it easier rather than it being a nuisance. Practically the same reason API things like :GetChildren() and the parent parameter for Instance.new() is here.
EDIT:
[size=4]Changes to the :GetProperty have been changed. I have added added optional parameters in which you can see by referencing back to the property explanation.[/size]
Editing this thread to address on “Why do I want this?”
One obvious thing is that it helps make code cleaner. You can get the properties in a single method instead of spending several lines getting them.
Also, these methods overall provides a nice property handling solution again because you don’t have to do it all one by one.
Any feedback is appreciated!