Jump to content




[1.3] Tunnel Boring Machine Controle Code


  • You cannot reply to this topic
1 reply to this topic

#1 vvenaya

  • Members
  • 27 posts

Posted 25 February 2012 - 10:10 AM

Tunnel boring Machine

DESCRIPTION
The tunnel boring machine does what it says, it makes a tunnel 3x3 until you send a message to make it stop. After sending stop, the turtle returns to its original position

USAGE
From and computer send a word 'go' through rednet to the turtle's ID to start digging, and the word 'stop' to make it stop and return to its original location

Example: (in LUA)

   rednet.send(TurtleID,"go")
   rednet.send(TurtleID,"stop")


CODE
put this code on the turtle...

local maxDistance=40
local distanceTraveled=0

local function goDig()
   turtle.dig()
   turtle.forward()
   turtle.digUp()
   turtle.turnLeft()
   turtle.dig()
   turtle.up()
   turtle.dig()
   turtle.digUp()
   turtle.up()
   turtle.dig()
   turtle.turnRight()
   turtle.turnRight()
   turtle.dig()
   turtle.down()
   turtle.dig()
   turtle.down()
   turtle.dig()
   turtle.turnLeft()
end

local function stopDig()
   print("Program ended by user")
   for c = 1,distanceTraveled do turtle.back() end
   distanceTraveled = 0
end

rednet.open("right")

local command=""
local bDigging=false

while true do
parallel.waitForAll(
  function() _,_, command = os.pullEvent("rednet_message") end,
  function()
   repeat
	if bDigging then
	 print("digging")
	 goDig()
	 distanceTraveled=distanceTraveled+1
	 if distanceTraveled==maxDistance then command="stop" end
	end
	sleep(0.5)
   until command~=""
  end)
sleep(0.5)
if command=="go" then
  bDigging=true
elseif command=="stop" then
  bDigging=false
  stopDig()
end
command=""
end



Note: thanks Sumeth on making me start on this, not much left of your code though

#2 Bennievv

  • Members
  • 26 posts
  • LocationThe Netherlands

Posted 25 February 2012 - 10:20 AM

Hmmmm... looks nice! Thanks!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users