Posted 03 August 2014 - 11:12 PM
This program is supposed to build a 16x16 circular tower, but if I leave it running, it always ends up lopsided at random places.. I've even set multiple turtles to run it in a completely flat world, every turtle builds it different and the tower is never straight. I'm not sure if I need to add some extra code for lag/glitch correction, or if I am making an odd mistake somewhere. Here is the program:
-- Inventory Slot Variable
local p = 2
-- Repeat variable for up one level + full circle
local o = 1
-- Repeat variable for one quarter of a circle
local i = 1
-- consumes initial fuel, then selects slot 2, and turns on wifi
turtle.refuel(1)
turtle.select(2)
-- Function to get the number of items in a given slot
bcount = function()
return turtle.getItemCount(p)
end
-- Function to get the fuel level of the robot
fcount = function()
return turtle.getFuelLevel()
end
--[[ All in one check and fix function - it checks for empty item slots and moves
slot over when needed, and it checks for fuel level, and refules when needed
--]]
check = function()
if bcount() < 1 then
p = p + 1
turtle.select(p)
end
print ("My current fuel level is " .. fcount())
if fcount() < 1 then
print ("Attempting to eat my fuel...")
if turtle.getItemCount(1) < 1 then
print ("I am out of fuel...")
o = 0
end
turtle.select(1)
turtle.refuel(1)
turtle.select(p)
end
end
--[[ Basic right corner, it really just moves the turtle like so:
-->-->
|
-->-->
--]]
rCorner = function()
turtle.turnRight()
turtle.forward()
turtle.turnLeft()
end
--[[ Basic left corner, it really just moves the turtle like so:
-->-->
|
-->-->
--]]
lCorner = function()
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
end
-- Function for Place block down, and move forward, very common movement.
pfmove = function()
turtle.placeDown()
turtle.forward()
check()
end
--[[ Main code loop for creating a tower, it will continue until it runs out of
blocks or runs out of fuel (if it does run out of blocks, it will still move up
until it runs out of fuel)
--]]
repeat
turtle.up()
print("Attempting to build next level")
repeat
for t=1,5 do
pfmove()
end
rCorner()
for t=1,2 do
pfmove()
end
rCorner()
pfmove()
turtle.turnRight()
for t=1, 2 do
turtle.forward()
turtle.placeDown()
check()
end
lCorner()
turtle.forward()
i = i + 1
until i == 5
i = 1
until o == 0
Edited on 05 August 2014 - 06:22 AM