Posted 06 August 2012 - 10:51 AM
Intro of Awesomosity
Alright… So I noticed I needed 8 diamonds to make a quarry and I heard my friend talking about this mod called 'ComputerCraft' to make automated farms and such. I gave it a try and was overwhelmed by the possibilities…
I got the hang of lua pretty quick, so I decided to make a program for a quarry. It's now exactly 12 hours ago since I've discovered ComputerCraft, so you'll probably notice that the code isn't… optimal.
I begin by creating some variables:
x is vertical movement in the flat plane of minecraft
z is horizontal movement in the plane
y is up and down (lower is higher y values, sorry if you're confused ;)/>/> after all, this is ask the pros… :P/>/> )
c is the direction the turtle is aiming (1 being towards the positive x-axis, 2 the positive y- axis and so on to 4)
h is used to select the slots one after another, don't bother, I haven't implemented something that activates it yet.
i used alot of functions so I could repeat them as much as possible:
start(a, :(/>/> : used to start the quarry
noord() : this means 'north' in my language. i use it to move the turtle to the 'north' (positive x-axis)
zuid() : this means 'south', same use as 'north', only inversed.
dlinks() : makes the turtle turn left after going south.
drechts: makes the turtle turn right after going north.
save() : saves the current location, so the bot can return to where it was. not in use right now.
home () : makes the turtle go back to (1,0,1) (x,y,z)
drop() : drops the stuff. no use for now.
back() : returns after going home to the previous location. not in use right now.
west,up,down,south,east () : moves the turtle in that direction to the edge.
draai: turns the turtle like the previous position. not in use.
My error is the following: bios:206: [string "quarry"]:21: 'then' expected
I already have a then there, and I'm pretty sure I didn't forgot a 'end'.
Also… Is there a way to stop the pocess when the turtle is full, and then let him carry on what he was doing? If so, is there a possibility you could explain it? Since a while function over the whole code will just randomly stop wthin the program.
I wrote this in a 3 hour time span: (I indented it as much as possible, sorry if you're confused)
Alright… So I noticed I needed 8 diamonds to make a quarry and I heard my friend talking about this mod called 'ComputerCraft' to make automated farms and such. I gave it a try and was overwhelmed by the possibilities…
I got the hang of lua pretty quick, so I decided to make a program for a quarry. It's now exactly 12 hours ago since I've discovered ComputerCraft, so you'll probably notice that the code isn't… optimal.
I begin by creating some variables:
x is vertical movement in the flat plane of minecraft
z is horizontal movement in the plane
y is up and down (lower is higher y values, sorry if you're confused ;)/>/> after all, this is ask the pros… :P/>/> )
c is the direction the turtle is aiming (1 being towards the positive x-axis, 2 the positive y- axis and so on to 4)
h is used to select the slots one after another, don't bother, I haven't implemented something that activates it yet.
i used alot of functions so I could repeat them as much as possible:
start(a, :(/>/> : used to start the quarry
noord() : this means 'north' in my language. i use it to move the turtle to the 'north' (positive x-axis)
zuid() : this means 'south', same use as 'north', only inversed.
dlinks() : makes the turtle turn left after going south.
drechts: makes the turtle turn right after going north.
save() : saves the current location, so the bot can return to where it was. not in use right now.
home () : makes the turtle go back to (1,0,1) (x,y,z)
drop() : drops the stuff. no use for now.
back() : returns after going home to the previous location. not in use right now.
west,up,down,south,east () : moves the turtle in that direction to the edge.
draai: turns the turtle like the previous position. not in use.
My error is the following: bios:206: [string "quarry"]:21: 'then' expected
I already have a then there, and I'm pretty sure I didn't forgot a 'end'.
Also… Is there a way to stop the pocess when the turtle is full, and then let him carry on what he was doing? If so, is there a possibility you could explain it? Since a while function over the whole code will just randomly stop wthin the program.
I wrote this in a 3 hour time span: (I indented it as much as possible, sorry if you're confused)
function start(a,:D/>/>
x=1
y=0
z=1
c=1
h=1
do
turtle.digDown()
turtle.down()
noord()
end
end
function noord()
if x<a then do
turtle.dig()
turtle.forward()
x=x+1
noord()
end
else
if z=a and y=b then
home()
end
end
if z=a and y<b
then
do
turtle.turnLeft()
west()
turtle.turnLeft()
zuid()
turtle.turnLeft()
turtle.turnLeft()
turtle.digDown()
turtle.down()
y=y+1
c=1
noord()
end
end
if z<a then do
drechts()
end
end
end
end
function zuid()
if x>1 then do
turtle.dig()
turtle.forward()
x=x-1
zuid()
end
else
if z=a and y=b then do
home()
end
end
if z=a and y<b then do
turtle.turnRight()
west()
turtke.turnRight()
c=1
turtle.digDown()
turtle.down()
noord()
end
end
if z<a then do
dlinks()
end
end
end
end
function dlinks()
do turtle.turnLeft()
c=2
turtle.dig()
turtle.forward()
z=z+1
turtle.turnLeft()
c=1
noord()
end
end
function drechts()
do turtle.turnRight()
c=2
turtle.dig()
turtle.forward()
z=z+1
turtle.turnRight()
c=3
zuid()
end
end
function save()
d=x
e=y
f=z
g=c
end
function home()
if c<4 then do
turtle.turnRight()
c=c+1
home()
else
up()
west()
turtle.turnLeft()
south()
end
end
end
function drop()
if h<10 then do
turtle.select(h)
turtle.drop
h=h+1
end
else
h=1
end
end
function back()
do turtle.turnLeft()
east()
turtle.turnLeft()
north()
down()
c=1
draai()
x=d
y=e
z=f
c=g
end
end
function west()
if z>1 then do
turtle.forward()
z=z-1
west()
end
end
end
function up()
if y>0 then do
turtle.up()
y=y-1
up()
end
end
end
function down()
if y<e then do
turtle.down()
y=y+1
down()
end
end
end
function south()
if x>1 then do
turtle.forward
x=x-1
south()
end
end
end
function east()
if z<f then do
turtle.forward()
z=z+1
east()
end
end
end
function draai()
if c<g then do
turtle.turnRight()
c=c+1
draai()
end
end
end