CorianWornen Posted June 8, 2012 Posted June 8, 2012 I play on a tekkit server that still holds Computercraft and I have a question in regards to it. Is there a page anywere that has a reliable list of lua commands, as well as minecraft specific commands including what they do. The reason I ask is that I want to write (or find) a program for a mining turtle that will flatten land from it's starting position and up (taking and x,y,z input), while avoiding dangerous materials, namely lava. However I can't find the information I need, and my searches for such a program have provided no way to use them. I am not running the server so I can't just install it into the files, so I need something I can just type in. Either a link, or a code would be greatly appreciated.
Iscamania Posted June 8, 2012 Posted June 8, 2012 Start looking at the wiki of Computercraft and ask on their forum about this. They're gonna be a better help (if you lucky) than us here.
rich1051414 Posted June 12, 2012 Posted June 12, 2012 I wrote a simple program that flattens land. Maybe it will help. It doesnt detect dangerous blocks but i only use it above water level anyways. It mines a cube and its starting position is the bottom front left corner. You have to modify two variables because i can't be bothered to add an argument handler. area = 16 --length of sides height = 30 --how high it needs to go direction = false for x = 1, height do for xx = 1, area - 1 do for xxx = 1, area do repeat turtle.dig() until turtle.forward() == true end if direction == false then direction = true turtle.turnRight() repeat turtle.dig() until turtle.forward() == true turtle.turnRight() else direction = false turtle.turnLeft() repeat turtle.dig() until turtle.forward() == true turtle.turnLeft() end end for xxx = 1, area do repeat turtle.dig() until turtle.forward() == true end if x < height then repeat turtle.digUp() until turtle.up() == true turtle.turnRight() turtle.turnRight() else turtle.turnRight() turtle.turnRight() end end for a = 1, height do turtle.down() ---return to ground level end
rich1051414 Posted June 13, 2012 Posted June 13, 2012 This morning i was asked a few questions so i'm going to update the code to include comments and to allow arguments. It also has a block counter just for curiosity sake. I can add a few lines to detect when it is finished, if you ask. I thought a manual entry for height allowed for more flexible usage tho(like clearing an underground chamber), so i left it out. when you run the script, use this syntax: turtleFlatten [length] [width] [height] like this: turtleFlatten 16 8 20 This will mine 16x8x20 blocks. --TurtleFlatten --rich1051414 -------------------------------------------------- --Sends turtle out to flatten a plot land -------------------------------------------------- --Check arguments for correct formatting local args = { ... } if #args ~= 3 then --Check if it's not exactly 3 arguments. shell.run("clear") print("Invalid number of arguments") print("turtleflatten [length] [width] [height]") do return end end for i = 1, 3 do --Step through each argument and make sure it is a number greater than 1. if tonumber(args[i]) < 2 then shell.run("clear") print("Invalid arguments") print("All measurements must be numbers greater than 1") do return end end end -------------------------------------------------- --commandline arguments [length] [width] [height] length = tonumber(args[1]) --length of square width = tonumber(args[2]) --width of square height = tonumber(args[3]) --how high it needs to go -------------------------------------------------- -------------------------------------------------- -- Now for the logic -------------------------------------------------- -- Boolean to remember which way to turn. direction = false LayerBlockCount = 0 TotalBlocksBusted = 0 ------------------------------------------ -- Nested loops, 1 each for length width and height. shell.run("clear") print("Flatten land initialized.\n") write("Length: ") write(tostring(length)) write(" Width: ") write(tostring(width)) write(" Height: ") write(tostring(height)) print("\n\n\n") for x = 1, height do write("Layer ") write(tostring(x)) write(" started.\n\n") for xx = 1, width - 1 do for xxx = 1, length do --Digs until the turtle can move forward, to deal with gravel and sand. repeat if turtle.detect() then TotalBlocksBusted = TotalBlocksBusted + 1 end turtle.dig() until turtle.forward() == true -------------------------------------------------- end -- Orientation. if direction == false then direction = true turtle.turnRight() repeat if turtle.detect() then TotalBlocksBusted = TotalBlocksBusted + 1 end turtle.dig() until turtle.forward() == true turtle.turnRight() else direction = false turtle.turnLeft() repeat if turtle.detect() then TotalBlocksBusted = TotalBlocksBusted + 1 end turtle.dig() until turtle.forward() == true turtle.turnLeft() end -------------------------------------------------- end -- Last line finished outside of loop to remove unneeded steps. for xxx = 1, length do repeat if turtle.detect() then TotalBlocksBusted = TotalBlocksBusted + 1 end turtle.dig() until turtle.forward() == true end -------------------------------------------------- --Checks if it needs to go up or just turn around for completion. if x < height then repeat if turtle.detectUp() then TotalBlocksBusted = TotalBlocksBusted + 1 end turtle.digUp() until turtle.up() == true turtle.turnRight() turtle.turnRight() else turtle.turnRight() turtle.turnRight() end -------------------------------------------------- end print("Job Completed.\n") --Return turtle to starting point(if all dimensions are even numbers) print("Returning...\n") for a = 1, height do turtle.down() end write(tostring(TotalBlocksBusted)) write(" total blocks busted.\n\n") print("Powering down.\n") --------------------------------------------------
warpspeed10 Posted June 13, 2012 Posted June 13, 2012 Thank you for the code sample. I never realized the movement functions returned a Boolean upon success or failure. I'll have to go play with my turtle later to try this out.
rich1051414 Posted June 13, 2012 Posted June 13, 2012 it wouldn't be entirely necessary, but makes dig loops in case of gravel and sand a couple lines shorter to code. You can also turtle.detect for all directions, but it only returns a Boolean and only detects solid blocks(detects snow even tho it doesnt have to mine snow to move however). I do not think there is a way to check for fluid blocks at all, but the turtle is immune to lava and water anyways.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now