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

Function help

Started by joshxl, 03 October 2012 - 11:33 AM
joshxl #1
Posted 03 October 2012 - 01:33 PM
Hello there is an error with my code and i have been stuffing around with it for about an hour trying to get it to work but i have given up
and could use some assistance this is probably simple too so.
My error is its expecting an end to close the function
on line 1

function wallOne()
for i = 1, 14 do
local itemcount
itemcount = turtle.getItemCount(1)
if itemcount == 0 then
  turtle.select(2)
else
  turtle.select(1)
  turtle.place()
  turtle.up()
  turtle.place()
  turtle.up()
  turtle.place()
  turtle.up()
  turtle.select(5)
  turtle.place()
  turtle.up()
  turtle.place()
  turtle.up()
  turtle.place()
  turtle.up()
  turtle.place()
  turtle.up()
  turtle.place()
  turtle.back()
  turtle.down()
  turtle.down()
  turtle.down()
  turtle.down()
  turtle.down()
  turtle.down()
  turtle.down()
  end
end

wallOne()
KaoS #2
Posted 03 October 2012 - 01:44 PM

function wallOne()
  for i = 1, 14 do
  if turtle.getItemCount(1)==0 then
   turtle.select(2)
  else
   turtle.select(1)
  end
  for i=1,3 do
   turtle.place()
   turtle.up()
  end
  turtle.select(5)
  for i=1,4 do
   turtle.place()
   turtle.up()
  end
  turtle.place()
  turtle.back()
  for i=1,7 do
   turtle.down()
  end
end
wallOne()

if it errors then please give the error
joshxl #3
Posted 03 October 2012 - 02:03 PM
Same as before 'end' expected (to close 'function' at line 1)
Klausar #4
Posted 03 October 2012 - 02:13 PM
You forgot to close the first "for-loop" since the first end closes the ifelse.
jag #5
Posted 03 October 2012 - 02:54 PM
As Klausar said
You forgot to close the first "for-loop".
So your code should be like this:
Spoiler
function wallOne()
  for i = 1, 14 do
    local itemcount
    itemcount = turtle.getItemCount(1)
    if itemcount == 0 then
      turtle.select(2)
    else
      turtle.select(1)
      turtle.place()
      turtle.up()
      turtle.place()
      turtle.up()
      turtle.place()
      turtle.up()
      turtle.select(5)
      turtle.place()
      turtle.up()
      turtle.place()
      turtle.up()
      turtle.place()
      turtle.up()
      turtle.place()
      turtle.up()
      turtle.place()
      turtle.back()
      turtle.down()
      turtle.down()
      turtle.down()
      turtle.down()
      turtle.down()
      turtle.down()
      turtle.down()
    end
  end
end

wallOne()
Or do like Kaos did:
Spoiler
function wallOne()
  for i=1,14 do
    if turtle.getItemCount(1)==0 then
      turtle.select(2)
    else
      turtle.select(1)
    end
    for i=1,3 do
      turtle.place()
      turtle.up()
    end
    turtle.select(5)
    for i=1,4 do
      turtle.place()
      turtle.up()
    end
    turtle.place()
    turtle.back()
    for i=1,7 do
      turtle.down()
    end
  end
end

wallOne()
joshxl #6
Posted 03 October 2012 - 09:32 PM
Oh wow 3 ends haha i dont completely understand why but whatever thanks :(/>/>
Fatal_Exception #7
Posted 03 October 2012 - 10:50 PM
– End if
– End for
– End function
Kingdaro #8
Posted 04 October 2012 - 12:00 AM

function ALWAYS()
 if END then
  for i=1, THESE do
   while LINES do

   end
  end
 end
end