generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Lua should put in :FindFirstParent("")

Previous Thread :: Next Thread 
kingmatt2 is not online. kingmatt2
Joined: 20 Aug 2011
Total Posts: 6494
09 Feb 2014 12:21 PM
It goes though all the parents of parents of a part until it find the one with the name in the ""
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
09 Feb 2014 12:22 PM
>Lua should put in
>Lua


Its a roblox specific function.
Report Abuse
kingmatt2 is not online. kingmatt2
Joined: 20 Aug 2011
Total Posts: 6494
09 Feb 2014 12:23 PM
Oh. I thought it could spread to different engines.
Report Abuse
AbsoluteLOL is not online. AbsoluteLOL
Joined: 01 Dec 2012
Total Posts: 3939
09 Feb 2014 12:23 PM
I swear you don't know anything about half of the things you talk about kingmatt...
Report Abuse
toshir0z is not online. toshir0z
Joined: 03 Nov 2009
Total Posts: 425
09 Feb 2014 12:29 PM
function findFirstParent(Object,Name)
while true do
Object = Object.Parent
if(Object == game)then return name end
if(Object.Name:find(Name) ~= nil)then return Object end
end
end

There is functions for a reason.
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
09 Feb 2014 12:30 PM
._.

I tried to facepalm

but the stupidity in this thread is too great. I need to find a cliff and take a dive.
Report Abuse
TheOneSwordfighter is not online. TheOneSwordfighter
Joined: 18 Feb 2013
Total Posts: 212
09 Feb 2014 12:31 PM
@toshir0z,
I disagree. There are functions for a reason.

~LuaWeaver; Programmer, gamer, developer.
Report Abuse
MettaurSp is not online. MettaurSp
Joined: 20 Mar 2010
Total Posts: 3179
09 Feb 2014 12:32 PM
he wat
Report Abuse
toshir0z is not online. toshir0z
Joined: 03 Nov 2009
Total Posts: 425
09 Feb 2014 12:33 PM
Why should I use proper grammar when I honestly don't care about this thread at all.
Report Abuse
bohdan77 is not online. bohdan77
Joined: 10 Aug 2008
Total Posts: 7944
09 Feb 2014 12:34 PM
Oh my.
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
09 Feb 2014 12:54 PM
Recursion :D
findFirstParent = (object, name) -> object if object.Name is name or object is game else findFirstParent object.Parent, name
Report Abuse
kingmatt2 is not online. kingmatt2
Joined: 20 Aug 2011
Total Posts: 6494
09 Feb 2014 12:55 PM
At least one person thought it was a good idea-ish..

Report Abuse
awsumpwner27 is not online. awsumpwner27
Joined: 03 Sep 2011
Total Posts: 4389
09 Feb 2014 01:15 PM
A strange idea. There should be lists of parts to be more specific.
Report Abuse
kingmatt2 is not online. kingmatt2
Joined: 20 Aug 2011
Total Posts: 6494
09 Feb 2014 01:18 PM
:FindFirstParent(Part,Name,NumOfPartsUntilName)
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
09 Feb 2014 01:28 PM
I would prefer a GetDescendants method... I know that with recursion its possible, but that seems too... laggy D:
Report Abuse
MettaurSp is not online. MettaurSp
Joined: 20 Mar 2010
Total Posts: 3179
09 Feb 2014 01:53 PM
function GetDescendants(object)
local objectTable = {}
local nextObjects = {object}
local currentObjects
repeat
currentObjects = nextObjects
nextObjects = {}
for i,v in pairs(currentObjects) do
for a,c in pairs(v:children()) do
nextObjects[#nextObjects + 1] = c
end
objectTable[#objectTable + 1] = v
end
until #nextObjects==0
return objectTable
end
This took ~4.8438 seconds when run with 'game' as the argument 1000 times, so about .0048 per call. That fast enough? o3o 778 descendants btw.
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
09 Feb 2014 01:56 PM
Nowhere near fast enough :<

Try

GetDescendants = function(o, t)
local t = t or {}
for i, v in ipairs(o:GetChildren()) do
table.insert(t, v)
GetDescendants(v, t)
end
return t
end
Report Abuse
AbsoluteLOL is not online. AbsoluteLOL
Joined: 01 Dec 2012
Total Posts: 3939
09 Feb 2014 02:18 PM
function GetDescendants(dir, _return)
local result = ((type(_return) == "table") and _return) or { }

for index, value in pairs (dir:GetChildren()) do
result[index] = value
GetDescendants(value, result)
end

return result
end

Took 0.022 seconds to get 5000 descendants.
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
09 Feb 2014 02:29 PM
@|LOL|: Would that not cause some indexes to be overridden?

And why not just use "result = result or {}", instead of that type stuff? :P
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
09 Feb 2014 02:30 PM
So it has to be a table
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
09 Feb 2014 02:31 PM
Well if you put something that ISN'T a table there you are an idiot and should learn how to script.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
09 Feb 2014 02:38 PM
If you are releasing it to the public then you know idiots may have it c;
If not, you don't even need to check if it is nil or not
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
09 Feb 2014 02:40 PM
I guess I could just shove a table in there.
Report Abuse
MettaurSp is not online. MettaurSp
Joined: 20 Mar 2010
Total Posts: 3179
09 Feb 2014 03:22 PM
Results from testing with 10777 objects in the game and 1000 calls for each, with an average of 10 of each of those 1k loops. Took about 30 minutes o3o. Functions: 1 = mine, 2 = not's, 3 = abs'.

return function()
function g1(object)
local objectTable = {}
local nextObjects = {object}
local currentObjects
repeat
currentObjects = nextObjects
nextObjects = {}
for i,v in pairs(currentObjects) do
for a,c in pairs(v:children()) do
nextObjects[#nextObjects + 1] = c
end
objectTable[#objectTable + 1] = v
end
until #nextObjects==0
return objectTable
end

function g2(o, t)
local t = t or {}
for i, v in ipairs(o:GetChildren()) do
table.insert(t, v)
g2(v, t)
end
return t
end

function g3(dir, _return)
local result = ((type(_return) == "table") and _return) or { }

for index, value in pairs (dir:GetChildren()) do
result[index] = value
g3(value, result)
end

return result
end

print("GetDescendants1")
total = 0
for i=1,10 do
wait()
local t = tick()
for a=1,1000 do
g1(game)
end
total = total + (tick()-t)
print((i*10).."%")
end
print("Average time: "..(total/10))
t1 = total/10
print("GetDescendants2")
total = 0
for i=1,10 do
wait()
local t = tick()
for a=1,1000 do
g2(game)
end
total = total + (tick()-t)
print((i*10).."%")
end
print("Average time: "..(total/10))
t2 = total/10
print("GetDescendants3")
total = 0
for i=1,10 do
wait()
local t = tick()
for a=1,1000 do
g2(game)
end
total = total + (tick()-t)
print((i*10).."%")
end
print("Average time: "..(total/10))
num = g1(game)
print("Final Results ("..num.." instances): GetDescendants1 ("..t1.."), GetDescendants2 ("..t2.."), GetDescendants3("..(total/10)..")")
end

> require(Workspace.ModuleScript)()
GetDescendants1
10%
20%
12:44:52.622 - Auto-Saving...
30%
40%
50%
60%
70%
12:49:52.690 - Auto-Saving...
80%
90%
100%
Average time: 64.599093365669
GetDescendants2
10%
20%
12:54:52.759 - Auto-Saving...
30%
40%
50%
60%
12:59:52.826 - Auto-Saving...
70%
80%
90%
100%
Average time: 65.884693050385
GetDescendants3
10%
13:04:52.893 - Auto-Saving...
20%
30%
40%
50%
13:09:52.961 - Auto-Saving...
60%
70%
80%
90%
13:14:53.030 - Auto-Saving...
100%
Average time: 69.340808653831
Final Results: GetDescendants1 (64.599093365669), GetDescendants2 (65.884693050385), GetDescendants3(69.340808653831)
Report Abuse
MettaurSp is not online. MettaurSp
Joined: 20 Mar 2010
Total Posts: 3179
09 Feb 2014 03:24 PM
'Final Results: ..." Ignore dat extra stuff, edited it a bit after the run to include the number of children, but didn't wanna run another 30 min loop o3o
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image