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: recurring function false negative

Previous Thread :: Next Thread 
Qorm is not online. Qorm
Joined: 25 Jul 2010
Total Posts: 1650
05 May 2016 11:38 PM
function findPart(startPoint, objectToFind) --object, string
if startPoint.Name == objectToFind then
print"yay"
return true
end
for _, v in pairs(startPoint:GetChildren()) do
findPart(v, objectToFind)
end
end

if findPart(script.Parent, "Part") then
print"a"
else
print"b"
end

output:
yay
b

it finds the part and returns true but the if statement says otherwise


Report Abuse
GetTheJobDone is not online. GetTheJobDone
Joined: 20 Apr 2016
Total Posts: 3008
05 May 2016 11:46 PM
Oh, I think what's happening is it's returning the function to itself with the recursive call.

I guess you have to keep returning up the stack trace to the original function?


Report Abuse
Wayne_Gretzky is not online. Wayne_Gretzky
Joined: 03 Apr 2008
Total Posts: 78011
05 May 2016 11:47 PM
Ye, ur missing a return
When u call findPart from the for loop, you have to return the result of that
Report Abuse
Wayne_Gretzky is not online. Wayne_Gretzky
Joined: 03 Apr 2008
Total Posts: 78011
05 May 2016 11:48 PM
....although its a for loop.
So keep a variable, if that variable gets set to true then you return
Report Abuse
GetTheJobDone is not online. GetTheJobDone
Joined: 20 Apr 2016
Total Posts: 3008
05 May 2016 11:48 PM
Oh, nevermind, it's not recursive, it's only a static level deep. So just return from THAT.


Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
06 May 2016 12:01 AM
if script.Parent:FindFirstChild("Part",true) then
print("Found part")
else
print("No part exists")
end


Report Abuse
Qorm is not online. Qorm
Joined: 25 Jul 2010
Total Posts: 1650
06 May 2016 12:06 AM
@TimeTicks, same issue

function findPart(startPoint, objectToFind) --object, string
if startPoint.Parent:findFirstChild(objectToFind) then
print"yay"
return true
end
for _, v in pairs(startPoint:GetChildren()) do
findPart(v, objectToFind)
end
end

if findPart(script.Parent, "Part") then
print"a"
else
print"b"
end

output:

yay
b


Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
06 May 2016 12:08 AM
Qorm, what I was saying is your function is stupid and useless, just use findfirstchild with recursion.


Report Abuse
Qorm is not online. Qorm
Joined: 25 Jul 2010
Total Posts: 1650
06 May 2016 12:09 AM
i need a recursion because what if i need to search through multiple parts and models etc


Report Abuse
Qorm is not online. Qorm
Joined: 25 Jul 2010
Total Posts: 1650
06 May 2016 12:10 AM
oh well could i have an example plz


Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
06 May 2016 12:10 AM
...Findfirstchild already has that

http://wiki.roblox.com/index.php?title=API:Class/Instance/FindFirstChild


Report Abuse
Qorm is not online. Qorm
Joined: 25 Jul 2010
Total Posts: 1650
06 May 2016 12:12 AM
wwwwwwwwwwwwwttttttttttffffffffffffffffffffffffffffffffffffffffff wow thanks


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