Posted 19 June 2013 - 07:06 PM
I just wrote my first program and cannot figure out why it is not running correctly. The goal is to have a turtle pull from a chest on its left, enchant the book, then drop it in the chest on the right. Currently it will turn left then end the program. Anyone have any tips?
--Wrap peripherals
local m = peripheral.wrap("right")
--set autocollect xp true
m.setAutoCollect(true)
--set variables
currLevel = m.getLevels()
--functions
--pulls books from chest
function getBooks()
print("Getting Book")
turtle.select(1)
turtle.suck()
if false then
print("Need more books!!")
sleep(15)
getBooks()
else
turtle.drop(turtle.getItemCount(1)-1)
end
end
--places enchanted books into chest
function storeBooks()
turtle.drop()
if false then
print("Chest full!!")
pause(15)
storeBooks()
end
end
--main enchant function
function enchantBook()
turtle.turnLeft()
getBooks()
m.enchant(30)
turtle.turnRight()
turtle.turnRight()
storeBooks()
turtle.turnLeft()
end
--main loop
while true do
print("Currently Level: "..currLevel.."")
if currLevel >=30 then
enchantBook()
else
sleep(10)
end
end