Posted 01 May 2012 - 11:08 AM
greetings everyone, I just want to share a program I made. It's my very first attempt at scripting in LUA, ever.
called "Flatit", it can be used to flat a vast area, as long as the tutle have sufficient blocks in the inventory. It can flat both ways, so it will still flat an area even if there's a depression or a hill.
Just place the Turtle in the desired elevation and run the program. one limitation is that it thinks that a wild grass is a block, so if a wild grass happens to be at the correct flat elevation as the starting point, it ignores it. so you have to do grass check manually after the turtle finished its job
here's the code:
I know, the code might be very messy, inefficient and all, but its my first attempt in scripting in LUA. so please dont be too harsh on me :)/>/>
RXDV Laboratories is my fictional company where i create all my program in. Just to add a little roleplay value :)/>/>
might as well create full suite of turtle programs.i am just sooo interested in turtles!
comments and suggestions please
called "Flatit", it can be used to flat a vast area, as long as the tutle have sufficient blocks in the inventory. It can flat both ways, so it will still flat an area even if there's a depression or a hill.
Just place the Turtle in the desired elevation and run the program. one limitation is that it thinks that a wild grass is a block, so if a wild grass happens to be at the correct flat elevation as the starting point, it ignores it. so you have to do grass check manually after the turtle finished its job
here's the code:
Spoiler
local function printheader()
term.clear()
term.setCursorPos(1,1)
print("-----------------------------------")
print("FlatIt | RXDV Laboratories")
print("-----------------------------------")
end
local function invcheck()
while true do
for n=1,9 do
if turtle.getItemCount(n) > 0 then
return n
end
end
printheader()
print("")
print("")
print("ERROR: No Blocks in Inventory. ")
print(" Please load any block into ")
print(" inventory.")
sleep(1)
end
end
local function eatforward()
-- x,y,z = gps.locate( 2, true )
while not turtle.detectDown() do
turtle.down()
dy = dy - 1
end
while dy < 0 do
turtle.up()
dy = dy + 1
turtle.select(invcheck())
turtle.placeDown()
end
while turtle.detect() do
turtle.dig()
turtle.up()
dy = dy + 1
end
while dy > 0 do
turtle.down()
dy = dy - 1
end
turtle.forward()
print("nom")
end
local function checkturn()
if curdir == 0 then
if dir == "left" then
curdir = 1
turtle.turnLeft()
eatforward()
turtle.turnLeft()
print("1")
return true
end
if dir == "right" then
curdir = 1
turtle.turnRight()
eatforward()
turtle.turnRight()
print("2")
return true
end
end
if curdir == 1 then
if dir == "right" then
curdir = 0
turtle.turnLeft()
eatforward()
turtle.turnLeft()
print("3")
return true
end
if dir == "left" then
curdir = 0
turtle.turnRight()
eatforward()
turtle.turnRight()
print("4")
return true
end
end
end
local function eatfar()
while ddist < dist do
ddist = ddist + 1
-- eaten = eaten + 1
eatforward()
end
end
local function eatall()
while dside < side do
eatfar()
ddist = 0
checkturn()
dside = dside + 1
end
eatfar()
end
local tArgs = { ... }
if #tArgs < 3 then
printheader()
print("Land Flatter for Turtles. by Dalva")
print("")
print("")
print("USAGE : flatit <left/right> ")
print(" <length> <width>")
print("EX : flatit 10 right 5")
print("NOTE : Do not use in areas where ")
print(" trees are present.")
return false
end
if not tArgs[1] == left and tArgs[1] == right then
printheader()
print("")
print("")
print("ERROR: Unknown Direction: " ..tArgs[1])
print("Please input either left/right")
print("")
return false
end
dy = 0
ddist = 0
dside = 0
curdir = 0
dist = tonumber(tArgs[2])
side = tonumber(tArgs[3])
dir = (tArgs[1])
printheader()
print("")
print("")
print("Beginning Flattening Operation...")
print("Length : " ..dist)
print("Width : " ..side)
print("Direction : " ..dir)
print("")
eatall()
printheader()
print("")
print("")
print("SUCCESS: Flattening Completed")
RXDV Laboratories is my fictional company where i create all my program in. Just to add a little roleplay value :)/>/>
might as well create full suite of turtle programs.i am just sooo interested in turtles!
comments and suggestions please