Jump to content




can you call a function inside itself?


  • You cannot reply to this topic
1 reply to this topic

#1 subzero22

  • Members
  • 97 posts

Posted 19 January 2014 - 12:43 AM

I know you can call functions inside other functions. But can you call a function inside itself?

I would test this but right now at work and decided to edit one of my codes. Here's a snipit of my code so you know what I'm trying to ask.

function check()
  if s == 16 and turtle.getItemCount(16) >= 1 then
    print("Turtle ran out of resources to build with")
    print("Please refill turtle with needed blocks and")
    print("press any key to continue building")
    os.pullEven("key")
    s = 1
  end
  if turtle.compareTo(16) == false then
    s = s + 1
    turtle.select(s)
    check()
  end
end


#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 19 January 2014 - 01:29 AM

That's known as recursion. It's a useful tool for certain things, but if you just want code to keep looping, use an actual loop.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users