This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
hondarider58's profile picture

Coding for a miner turtle

Started by hondarider58, 09 April 2013 - 01:33 PM
hondarider58 #1
Posted 09 April 2013 - 03:33 PM
I need to figure out how to code my turtle to mine straight forward at 3 blocks high (3x1)
my code at the moment is

turtle.refuel()
print("Refuled turtle!") do
turtle.digForward()
turtle.forward()
turtle.digUp()
turtle.up()


im not going though the whole code because its basically the same with 1 end and the bottom
i get this attempt to call nil error and i dont know what im doing wrong.
please help
Dlcruz129 #2
Posted 09 April 2013 - 03:38 PM
I need to figure out how to code my turtle to mine straight forward at 3 blocks high (3x1)
my code at the moment is

turtle.refuel()
print("Refuled turtle!") do
turtle.digForward()
turtle.forward()
turtle.digUp()
turtle.up()


im not going though the whole code because its basically the same with 1 end and the bottom
i get this attempt to call nil error and i dont know what im doing wrong.
please help

turtle.digForward() should be turtle.dig()
theoriginalbit #3
Posted 09 April 2013 - 05:06 PM
if you find yourself making this mistake quite often it may be worth you putting this line of code at the top of your programs


turtle.digForward = turtle.dig

also if your code is just lots of what you have posted, then you are better to just have the code once and use a loop to have it run multiple times. for example

for i = 1, 10 do
  -- the code in here will run 10 times
end
it also means you can have a number that you start the program with to state how many times you want it to move

local times = tonumber( ... ) -- ... gets the arguments that the program was run with, in this case we are only using the first.
if not times then -- if they didn't give anything or it wasn't a number
  print("You did not tell me how many times to run") -- tell them off
  return -- dont run the rest of the program
end
for i = 1, times do
  -- this code will run as many times as is entered when running the program
end
hondarider58 #4
Posted 09 April 2013 - 05:38 PM
ok i have it working to the point where it does it once and then stops, i am going to put the code in for it to do it multiple times. but this is a quarry so is there an infinite code that the code runs infinity and i can just type in how far i want it to go?
hondarider58 #5
Posted 09 April 2013 - 05:49 PM
also where do i put the loop code, at the beginning before all of my commands or after them?
hondarider58 #6
Posted 09 April 2013 - 06:01 PM
disregard everything i have posted it is working now. :)/> one more question, is there a code for placing touches every like 12 blocks that would be amazing
theoriginalbit #7
Posted 09 April 2013 - 06:25 PM
there is a way to do it. you have to have a variable to track how far your turtle has moved, but take this code as an example.


for i = 1, 200 do -- repeat this code 200 times
  turtle.forward()
  if i % 12 == 0 then -- if the distance moved is a multiple of 12
    -- code to place the torch
  end
end
in this case i is the distance moved. if you use another kind of loop, you will need to add your own variable to track how many times it has moved.
hondarider58 #8
Posted 09 April 2013 - 06:38 PM
thanks this really helped. my hand are tired of writing code but it all good. should bring in a steady income of ores in FTB. :lol:/>