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

[LUA][Question] Turtle Mine Programm

Started by OneNonlyNova, 02 May 2012 - 12:45 PM
OneNonlyNova #1
Posted 02 May 2012 - 02:45 PM
Hey guys i've come accross this great mod 2 days ago and written a litte programm:


local tArgs = { ... }
steps = tonumber(tArgs[1])
if tArgs[2] ~= nil then
floors = tonumber(tArgs[2])
floors2 = floors-1
morefloors = true
end
turns = steps/2
steps2 = steps-1
durchlauf = 1
if turns == math.floor(turns) then
turns = math.floor(turns)
else
print("Die Zahl muss durch 2 teilbar sein!")
exit()
end
function digging()
for n=1, steps2 do
  while turtle.detect() do
   turtle.dig()
  end
  turtle.forward()
end
turtle.turnLeft()
while turtle.detect() do
	    turtle.dig()
    end
turtle.forward()
turtle.turnLeft()
for m=1,steps2 do
  while turtle.detect() do
   turtle.dig()
  end
  turtle.forward()
end
if durchlauf == turns then
  sleep(0.25)
  turtle.turnLeft()
  for k=1, steps2 do
   while turtle.detect() do
    turtle.dig()
   end
   turtle.forward()
  end
  turtle.turnLeft()
else
  turtle.turnRight()
  while turtle.detect() do
   turtle.dig()
  end
  turtle.forward()
  turtle.turnRight()
end
durchlauf = durchlauf+1
end
if morefloors == true then
for d=1, floors do
  durchlauf = 1
  for x=1,turns do
   digging()
  end
  if d == floors then
   for z=1,floors2 do
    turtle.down()
    sleep(0.25)
   end
   exit()
  else
   turtle.digUp()
   sleep(0.25)
   turtle.up()
  end
end
else
for x=1,turns do
digging()
end
end

what i want: put turtle down somewhere and dig - for example - 100x100x1 area return to start and if "morefloors" is on repeat this for the number of floors.

in general this is working great so far. i need this to get rid of some land and tree's and stuff in the air. i'm clearing a laaaarrggee area for my new homebase from
sky to badrock and it's a pain to remove all the dirt and wood/leaves) in a jungle biome :)/>/> therefore i thought this turtle's could do that.

now the problem: if i start the miner it works for a time but when i go afk (takes long time) the turtle messes up. sometimes i coudn't even find them again.
when i'm testing with like 4x4x4 area's it works great but larger scale seems to have problems.

i would love to get some response and tips to make my code better.


greetings,

nova
OneNonlyNova #2
Posted 02 May 2012 - 07:01 PM
another question, i'm trying now to link 10 or more turtle's to a hub and then let them all start and dig one block up in the sky this way i could remove many blocks relativly quickly.
but i have a problem with rednet. it seems that the broadcast aswell as send are bugged and only work sometimes, here my code:

hub:


rednet.open("left")
ids = {}
while true do
local sEvent, param1, param2 = os.pullEvent() -- Listen for events and two of their parameters.

if sEvent == "rednet_message" and param2 == "ping" then
  print ("Turtle " .. param1 .. " send a ping")
  table.insert(ids,param1)
  rednet.send(param1,"pong")
  print ("sending 'pong' back")
end

if sEvent == "char" and param1 == "l" then

  for i,v in ipairs(ids) do print(v) end

end

end
rednet.close("left")


turtles:


rednet.open( "right" )    -- Open the rednet-port on side 'sSide'
print ("RedNet online...")
while true do
local sEvent, param1, param2 = os.pullEvent() -- Listen for events and two of their parameters.
rednet.broadcast("ping")
print("sending Ping to Hub")
sleep(2)
if sEvent == "rednet_message" and param2 == "pong" then
  print("received pong")
  break
end
end
while true do
  print("connected")
  local sEvent, param1, param2 = os.pullEvent() -- Listen for events and two of their parameters.

  if sEvent == "char" and param1 == "q" then break end  -- Pressing q stops the program.
 
  if sEvent == "rednet_message" and param2 == "start" then
for n=1, 50 do
   while turtle.detectDown() do
    turtle.digDown()
   end
   turtle.down()
end
for n=1, 50 do
  turtle.up()
end
  end
 
  if sEvent == "rednet_message" and param2 == "next" then
while turtle.detect() do
   turtle.dig()
end
turtle.forward()
for n=1, 50 do
   while turtle.detectDown() do
    turtle.digDown()
   end
   turtle.down()
  end
  for n=1, 50 do
   turtle.up()
end
  end
 
end
rednet.close( "right" )   -- Close the rednet-port on side 'sSide'

currently i disabled the digging in the hub because i want to get the connection working probably first.

thanks in advance
MysticT #3
Posted 02 May 2012 - 09:36 PM
Well, I haven't read the entire code, but I think both problems are caused by the distance and not the programs.
For the first problem, you put the turtles to dig, then you go away, the chunk got unloaded, the turtle stopped working. You could use some other mod to keep the chunk loaded, otherwise you'll have to stay with your turtles all the time.
For the second, the problem might be the modem's range, it's only 64 blocks. You can change that in the config (just make sure to use forge version 100+ so config works).
OneNonlyNova #4
Posted 02 May 2012 - 11:02 PM
thanks for reply but the distance doesn't matter i tried a higher range and i have mod for keeping the chunks loaded. but in my test i'm standing right next to the computer and i have about 10 turtle's only a few blocks away.

got another idea?