Posted 06 December 2017 - 12:37 PM
Hi, I'm pretty new programming whit computercraft, I don't have all the knowledge yet. I wanted to make a program for a turtle to build a little house, whit the purpose of testing what I have learned, but I keep getting an error and I don't know what to do. Please help me.
The error is the following: build.house():1: index expected, got nil
And here is the code of the program, sorry if is a little messy, I tried my best to organize all the lines to be readable:
function floor.ceiling()
turtle.placeDown()
for a = 1,6 do
turtle.forward()
turtle.placeDown()
end
end
function wall.tile()
for a = 1,3 do
turtle.up()
turtle.placeDown()
end
end
function position()
turtle.turnLeft()
turtle.forward()
for a = 1,3 do
turtle.down()
end
end
function wall()
for a = 1,5 do
wall.tile()
turtle.forward()
for a = 1,3 do
turtle.down()
end
end
wall.tile()
position()
end
term.clear()
term.setCursorPos(1,1)
print ("Building…")
turtle.turnRight()
turtle.forward()
turtle.up()
turtle.select(1)
for a = 1,3 do
floor.ceiling()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
floor.ceiling()
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
end
floor.ceiling()
turtle.turnLeft()
turtle.forward()
turtle.select(2)
wall()
wall()
wall()
for b = 1,6 do
wall.tile()
turtle.forward()
for a = 1,3 do
turtle.down()
end
end
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.down()
turtle.down()
turtle.down()
turtle.turnLeft()
turtle.select(4)
turtle.place()
turtle.up()
turtle.turnLeft()
turtle.dig()
turtle.select(3)
turtle.place()
turtle.down()
turtle.turnLeft()
turtle.forward()
turtle.select(5)
turtle.place()
turtle.up()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.select(3)
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
turtle.forward()
turtle.down()
turtle.turnRight()
turtle.turnRight()
turtle.select(5)
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.up()
turtle.dig()
turtle.select(3)
turtle.place()
turtle.down()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
turtle.select(6)
turtle.place()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
turtle.place()
turtle.turnRight()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
turtle.up()
turtle.dig()
turtle.select(3)
turtle.place()
turtle.down()
turtle.turnRight()
turtle.forward()
turtle.select(7)
turtle.place()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
turtle.back()
turtle.back()
turtle.select(8)
turtle.place()
turtle.back()
turtle.down()
turtle.back()
turtle.select(9)
turtle.place()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
turtle.forward()
for c = 1,5 do
turtle.up()
end
turtle.forward()
turtle.select(1)
for d = 1,3 do
floor.ceiling()
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
floor.ceiling()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
end
floor.ceiling()
turtle.turnRight()
for e = 1,7 do
turtle.forward()
end
turtle.turnRight()
for f = 1,6 do
turtle.forward()
end
term.clear()
print ("Successful")
sleep(4)
term.clear()
term.setCursorPos(1,1)
The error is the following: build.house():1: index expected, got nil
And here is the code of the program, sorry if is a little messy, I tried my best to organize all the lines to be readable:
function floor.ceiling()
turtle.placeDown()
for a = 1,6 do
turtle.forward()
turtle.placeDown()
end
end
function wall.tile()
for a = 1,3 do
turtle.up()
turtle.placeDown()
end
end
function position()
turtle.turnLeft()
turtle.forward()
for a = 1,3 do
turtle.down()
end
end
function wall()
for a = 1,5 do
wall.tile()
turtle.forward()
for a = 1,3 do
turtle.down()
end
end
wall.tile()
position()
end
term.clear()
term.setCursorPos(1,1)
print ("Building…")
turtle.turnRight()
turtle.forward()
turtle.up()
turtle.select(1)
for a = 1,3 do
floor.ceiling()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
floor.ceiling()
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
end
floor.ceiling()
turtle.turnLeft()
turtle.forward()
turtle.select(2)
wall()
wall()
wall()
for b = 1,6 do
wall.tile()
turtle.forward()
for a = 1,3 do
turtle.down()
end
end
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.down()
turtle.down()
turtle.down()
turtle.turnLeft()
turtle.select(4)
turtle.place()
turtle.up()
turtle.turnLeft()
turtle.dig()
turtle.select(3)
turtle.place()
turtle.down()
turtle.turnLeft()
turtle.forward()
turtle.select(5)
turtle.place()
turtle.up()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.select(3)
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
turtle.forward()
turtle.down()
turtle.turnRight()
turtle.turnRight()
turtle.select(5)
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.up()
turtle.dig()
turtle.select(3)
turtle.place()
turtle.down()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
turtle.select(6)
turtle.place()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
turtle.place()
turtle.turnRight()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
turtle.up()
turtle.dig()
turtle.select(3)
turtle.place()
turtle.down()
turtle.turnRight()
turtle.forward()
turtle.select(7)
turtle.place()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
turtle.back()
turtle.back()
turtle.select(8)
turtle.place()
turtle.back()
turtle.down()
turtle.back()
turtle.select(9)
turtle.place()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
turtle.forward()
for c = 1,5 do
turtle.up()
end
turtle.forward()
turtle.select(1)
for d = 1,3 do
floor.ceiling()
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
floor.ceiling()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
end
floor.ceiling()
turtle.turnRight()
for e = 1,7 do
turtle.forward()
end
turtle.turnRight()
for f = 1,6 do
turtle.forward()
end
term.clear()
print ("Successful")
sleep(4)
term.clear()
term.setCursorPos(1,1)