Posted 22 June 2013 - 02:26 PM
Hi there.
Im new to both ComputerCraft and Lua, and i just wanted to ask you guys what you think about my code.
Ive been reading about lua for about 2 days now, and been making this program as ive learned.
code:
Please give me some feedback, and maybe something i could improve within the code or just make it more neat looking.
Thanks in advance.
Themaniacz
Im new to both ComputerCraft and Lua, and i just wanted to ask you guys what you think about my code.
Ive been reading about lua for about 2 days now, and been making this program as ive learned.
code:
local spot = 0
function move()
print("Moving")
for i=1,8 do
turtle.dig()
turtle.select(1)
turtle.forward()
turtle.digDown()
turtle.suckDown()
turtle.placeDown()
end
end
function main()
for i=1,4 do
move()
turnRight()
move()
turnLeft()
sleep(1)
end
end
function turnRight()
if true then
print("Turning right")
turtle.select(1)
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.digDown()
turtle.select(1)
turtle.placeDown()
end
end
function turnLeft()
if true then
print("Turning Left")
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.digDown()
turtle.select(1)
turtle.placeDown()
end
end
function unload()
num = 1
if true then
repeat turtle.back()
until turtle.detectDown()
for i=1,16 do
turtle.select(num)
turtle.dropDown()
num = num + 1
end
repeat turtle.forward()
until turtle.detectDown()
end
end
function takeSeed()
turtle.back()
turtle.suckDown(1,1)
turtle.forward()
end
function homeLine()
turtle.up()
turtle.up()
turtle.turnLeft()
for i=1,spot do
for i=1,10 do
turtle.forward()
end
end
turtle.turnRight()
turtle.down()
turtle.down()
end
function home()
if true then
turtle.turnLeft()
for i=1,8 do
turtle.forward()
end
turtle.turnRight()
for f= 1,9 do
turtle.back()
end
end
end
function run()
turtle.forward()
turtle.select(1)
turtle.digDown()
turtle.placeDown()
main()
move()
home()
unload()
end
function nextFarmLine()
turtle.turnRight()
for i=1,10 do
turtle.forward()
end
spot = spot + 1
end
function runWhat()
print ("What farm number should i move to?")
farmnum = read()
if farmnum == "1" then
print ("We already here at farm 1")
elseif farmnum == "2" then
print ("Moving to farm 2")
turtle.up()
turtle.up()
nextFarmLine()
turtle.down()
turtle.down()
turtle.turnLeft()
elseif farmnum == "3" then
print ("Moving to farm 3")
turtle.up()
turtle.up()
nextFarmLine()
nextFarmLine()
turtle.down()
turtle.down()
turtle.turnLeft()
else
print("Not a valid farmnumber")
end
write("To make me farm type run")
print("To take me home type home")
input = read()
if input == "run" then
takeSeed()
run()
homeLine()
elseif input == "home" then
if farmnum == "1" then
print("Im already home")
else
homeLine()
end
else
print("Not working yet")
end
end
runWhat()
Please give me some feedback, and maybe something i could improve within the code or just make it more neat looking.
Thanks in advance.
Themaniacz