Created
June 21, 2015 21:09
-
-
Save Adidea/5fc561e72f989abb2555 to your computer and use it in GitHub Desktop.
Create instances from a table against a list of prioritized properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function create(name, parent) | |
local priority = { | |
"BottomSurface", | |
"TopSurface", | |
"LeftSurface", | |
"RightSurface", | |
"FrontSurface", | |
"BackSurface", | |
"Shape", | |
"FormFactor", | |
"Anchored", | |
"Size", | |
"CFrame", | |
"Position", | |
} | |
local parentLast = nil | |
local function setPriorities(new, props) | |
for i,v in pairs(priority) do | |
if props[v] then | |
new[v] = props[v] | |
props[v] = nil | |
end | |
end | |
parentLast = props["Parent"] | |
props["Parent"] = nil | |
end | |
return function(props) | |
local new = Instance.new(name) | |
setPriorities(new, props) | |
for i, v in next, props do | |
if type(i) == 'number' then | |
v.Parent = new | |
else | |
new[i] = v | |
end | |
end | |
new.Parent = parentLast or parent | |
return new | |
end | |
end | |
local test = create("Part") { | |
TopSurface = "Smooth", | |
BottomSurface = "Smooth", | |
Anchored = true, | |
Shape = "Ball", | |
Position = Vector3.new(0, 10, 0), | |
Name = "Test", | |
Parent = workspace | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment