Ported Functions: Difference between revisions

Improvements
(started work for helpful article)
 
(Improvements)
Line 2: Line 2:


Modern versions of ROBLOX include many new features and functions which provide an easier experience for creators to make their own game. Because of this, older ROBLOX clients have far less features and therefore functions to offer. Fortunately, due to these limitations, ROBLOXians have — in the past, and in the now — made their own functions to serve the same purpose as their counterparts in the present.  
Modern versions of ROBLOX include many new features and functions which provide an easier experience for creators to make their own game. Because of this, older ROBLOX clients have far less features and therefore functions to offer. Fortunately, due to these limitations, ROBLOXians have — in the past, and in the now — made their own functions to serve the same purpose as their counterparts in the present.  
== WaitForChild ==
This function is a replacement for the function that's well known to most — if not all — scripters of ROBLOX. It keeps waiting until it finds a child with a specific name inside a specific parent. This kind of function can be found in old Animate scripts found inside a player's character!
<syntaxhighlight lang="lua">
local function waitForChild(parent, name)
while not parent:FindFirstChild(name, false) do
wait(0.03)
end


=WaitForChild=
return parent:FindFirstChild(name, false)
This function is a replacement for the function that's well known to most — if not all — scripters of ROBLOX. It keeps waiting until it finds a child with a specific name inside a specific parent. This kind of function can be found in old Animate scripts found inside a player's character!
{{code|lang=lua|
function WaitForChild(where, what) -- the "where" parameter is an object, and the "what" parameter is a string
while not where:FindFirstChild(what) do wait() end -- wait until finds the "what" string inside the "where" object
return where:FindFirstChild(what) -- return the child
end
end
}}
</syntaxhighlight>
== GetDescendants ==
This function is also considered a replacement to a very important function. It returns a table which contains all objects found within a requested object.
<syntaxhighlight lang="lua">
local function getDescendants(instance)
local descendants = {}


=GetDescendants=
for i, v in ipairs(instance:GetChildren()) do
This function is also considered a replacement to a very important function. It returns a table which contains all objects found within a requested object.
table.insert(descendants, v)
{{code|lang=lua|function GetDescendants(instance) -- the "instance" parameter is an object
 
local descendants {{=}} {}
for j, w in ipairs(getDescendants(v)) do
for i, v in pairs(instance:GetChildren()) do -- loop through children of parameter
table.insert(descendants, w)
table.insert(descendants, v) -- insert child into table
for j, w in pairs(GetDescendants(v)) do -- loops again by firing itself; creates a loop and returns itself until all children are found
table.insert(descendants, w) -- insert child of child of ... into table
end
end
end
end
return descendants -- returns all children found
return descendants -- returns all children found
end
end
}}
</syntaxhighlight>