This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
AndyMcB1's profile picture

which end for what

Started by AndyMcB1, 02 May 2013 - 12:23 AM
AndyMcB1 #1
Posted 02 May 2013 - 02:23 AM

function placer()
    while true do
    turtle.place()
    if turtle.getItemCount(1) <=5  then
    for slot=2,16 do
    turtle.transferTo(1, 3)
    end
    if turtle.back() == false then
    layer()
    rotate()
    end
    end
    end


can Lua tell which end goes with what or can i specify?
I didn't think spacing mattered for code..

Cheers!
Shnupbups #2
Posted 02 May 2013 - 02:32 AM
Yes, Lua will be able to tell which end goes with what. but to make it look better, make it:

function placer()
  while true do
    turtle.place()
    if turtle.getItemCount(1) <=5  then
      for slot=2,16 do
        turtle.transferTo(1, 3)
      end
      if turtle.back() == false then
        layer()
        rotate()
      end
    end
  end
end
You may have gotten an error with your previous code because you missed an end to close:

if turtle.getItemCount(1) <= 5 then
AndyMcB1 #3
Posted 02 May 2013 - 02:56 AM
Thanks :)/>

Do I need an 'end' for else statements or does that come within the if statement?
theoriginalbit #4
Posted 02 May 2013 - 03:15 AM
Do I need an 'end' for else statements or does that come within the if statement?

if statement syntax

if <condition> then
  -- code
end


if … else statement syntax

if <condition> then
  -- code
else
  -- code
end


if … elseif statement syntax

if <condition> then
  -- code
elseif <condition> then
  -- code
end

if … elseif … else statement syntax


if <condition> then
  -- code
elseif <condition> then
  -- code
else
  -- code
end

so as you can see only one end is required to close the statement.