Posted 03 June 2015 - 10:35 PM
Hi,
So I am making this program.
I kinda stole the idea of the "turtle swarm" program but wanted to try and make this but from scratch and slightly different.
So my problem is that when the "command" turtle places a turtle down I have to right click on the turtle in order for it to turn on. i.e. Dosn't startup by its self.
Here is the Command code:
And here is the turtle code:
HERE IS PASTEBIN FOR TURTLE RECEIVEING COMMANDS
HERE IS PASTEBIN FOR TURTLE SENDING COMMANDS
So I am making this program.
I kinda stole the idea of the "turtle swarm" program but wanted to try and make this but from scratch and slightly different.
So my problem is that when the "command" turtle places a turtle down I have to right click on the turtle in order for it to turn on. i.e. Dosn't startup by its self.
Here is the Command code:
Spoiler
rednet.open("right")
--[[ COMMANDER ]]--
--ID 11
--[[ VARIABLES ]]--
data = {}
data.X = 0
data.Y = 0
data.Z = 0
turtleAmount = 5 --# Amount of turtles user has inputted, will change so user has to input this number or count how many turtles there are.
currTurtlePlace = 0
function clear()
term.clear()
term.setCursorPos(1,1)
end
function sendData(x)
w=0
data.X = 0
data.Y = 3 * x
data.Z = -20
repeat
sleep(1)
rednet.broadcast(data)
w=w+1
until w == 5
term.setTextColor(colors.green)
clear()
print("Sent Data:\nX: "..data.X.. "\nY: "..data.Y.."\nX: "..data.X)
end
function turtlePlace()
repeat
currTurtlePlace = currTurtlePlace + 1
turtle.select(currTurtlePlace)
turtle.placeDown()
sendData(currTurtlePlace)
until currTurtlePlace == turtleAmount
end
turtlePlace()
Spoiler
rednet.open("right")
--[[ SLAVE ]]--
--ID 13
--[[ VARIABLES ]]--
dir={NORTH=0, EAST=1, SOUTH=2, WEST=3}
axis={X=0, Y=0, Z=0}
currDir = 0
faceingCorrect=false
facingCorrectY=false
enderChestSelect = 1
tunnelLength = 10
function digBlockFront()-- Digs block infront
while turtle.dig() do
if not turtle.detect() then
turtle.attack()
else
turtle.attack()
end
end
end
function digBlockUp()-- Digs block infront
while turtle.digUp() do
if not turtle.detectUp() then
turtle.attackUp()
else
turtle.attack()
end
end
end
function digBlockDown() -- Digs block downwards
while not turtle.digDown() do
if turtle.detectDown() then
turtle.digDown()
else
turtle.attackDown()
end
sleep(.5)
end
end
function mFwdDig() -- Move Forward and dig
while not turtle.forward() do
if turtle.dig() then
print("Block in the Way")
else
if turtle.attack() then
print("Attacking")
end
end
end
recordAxis()
return true
end
function mFwdNoDig() -- Moves forward if block in the way wont dig will attack
local moveForward = true
while not turtle.forward() do
if turtle.detect() then
print("Block in the way")
moveForward=false
break
elseif turtle.attack() then
print("Attacking")
end
end
if moveForward == true then
axis.Y=axis.Y+1
return true
else
return false
end
end
function mBck() -- Moves back if blocked returns false
local moveBack = true
while not turtle.back() do
moveBack = false
break
end
if moveBack == true then
axis.Y=axis.Y-1
return true
else
return false
end
end
function mDown() -- Move down and dig
while not turtle.down() do
if turtle.digDown() then
print("Block in the Way")
else
if turtle.attackDown() then
print("Attacking")
end
end
end
axis.Z=axis.Z-1
return true
end
function mUp() -- Move Up
while not turtle.up() do
if turtle.digUp() then
print("Block in the Way")
else
if turtle.attackUp() then
print("Attacking")
end
end
end
axis.Z=axis.Z+1
return true
end
function checkFaceDir() -- Checks the turtles facing Direction
if currDir == 4 then
currDir = 0
elseif currDir == -1 then
currDir = 3
end
end
function tLeft() -- Turns left
turtle.turnLeft()
currDir = currDir-1
checkFaceDir()
end
function tRight() -- Turns right
turtle.turnRight()
currDir = currDir+1
checkFaceDir()
end
function recordAxis() -- tells what axis to add to
if currDir == dir.NORTH then
axis.X = axis.X + 1
elseif currDir == dir.EAST then
axis.Y = axis.Y + 1
elseif currDir == dir.SOUTH then
axis.X = axis.X - 1
elseif currDir == dir.WEST then
axis.Y = axis.Y - 1
end
print("X: "..axis.X.." Y: "..axis.Y.." Z: ".. axis.Z)
end
function goTo(X,Y,Z) -- NORTH AND SOUTH IS X AXIS
--[[ X AXIS ]]--
faceingCorrect=false
while X ~= axis.X do -- Getting to X AXIS
print("Going To: "..X )
if X < axis.X then -- IF x is less than axis.X then turns to south
if currDir == dir.SOUTH then
print("Facing Correct DIRECTION")
else
while currDir ~= dir.SOUTH do
if currDir == dir.WEST then
tLeft()
elseif currDir == dir.EAST then
tRight()
else
tLeft()
tLeft()
end
end
end
faceingCorrect = true
elseif X > axis.X then -- IF x is greater than axis.X then turns to NORTH
if currDir == dir.NORTH then
print("Facing Correct DIRECTION")
else
while currDir ~= dir.NORTH do
if currDir == dir.WEST then
tRight()
elseif currDir == dir.EAST then
tLeft()
else
tLeft()
tLeft()
end
end
end
faceingCorrect = true
end
if faceingCorrect == true then
repeat
mFwdDig()
until X == axis.X
end
end
--[[ Y AXIS ]]--
while Y ~= axis.Y do -- Getting to Y AXIS
print("Going To Y: "..Y)
if Y < axis.Y then
if currDir == dir.WEST then
print("Facing Correct DIRECTION")
else
while currDir ~= dir.WEST do
if currDir == dir.NORTH then
tLeft()
elseif currDir == dir.SOUTH then
tRight()
else
tLeft()
tLeft()
end
end
end
facingCorrectY = true
elseif Y > axis.Y then
if currDir == dir.EAST then
print("Facing Correct DIRECTION")
else
while currDir ~= dir.EAST do
if currDir == dir.NORTH then
tRight()
elseif currDir == dir.SOUTH then
tLeft()
else
tLeft()
tLeft()
end
end
end
facingCorrectY = true
end
if facingCorrectY == true then
repeat
mFwdDig()
until Y == axis.Y
end
end
--[[ Z AXIS ]]--
while Z ~= axis.Z do -- Getting to Z AXIS
if Z > axis.Z then
repeat
mUp()
until Z == axis.Z
elseif Z < axis.Z then
repeat
mDown()
until Z == axis.Z
end
end
end
function placeChest() -- Places chest drops everything then takes chest back and sees if chest come back into slot 2
turtle.select(1)
getSlot = 1
data = turtle.getItemDetail()
x=3
if data.name == "EnderStorage:enderChest" then
turtle.select(enderChestSelect)
while not turtle.placeUp() do
if not turtle.digUp() then
turtle.attack()
end
end
repeat
turtle.select(x)
turtle.dropUp()
x=x+1
until x == 17
x=3
turtle.select(enderChestSelect)
turtle.digUp()
data = turtle.getItemDetail()
if data.name ~= "EnderStorage:enderChest" then
repeat
data2 = turtle.getItemDetail(getSlot)
getSlot = getSlot + 1
print(getSlot)
until data2.name == "EnderStorage:enderChest"
turtle.select(1)
turtle.dropDown()
turtle.select(getSlot)
turtle.transferTo(1, 32)
else
print("SUCCESS")
end
else
print("No Ender Chest")
end
turtle.select(1)
end
function receiveCmd() -- Works when gets command uses goTo function
id, data = rednet.receive()
print(data.X.. " / ".. data.Y .. " / " ..data.Z)
turtle.suck(1)
goTo(data.X, data.Y, data.Z)
end
function tDig() -- Will dig out a 3x3 tunnel
d = 0
repeat
tLeft()
digBlockFront()
mUp()
digBlockFront()
mUp()
digBlockFront()
tRight()
tRight()
digBlockFront()
mDown()
digBlockFront()
mDown()
digBlockFront()
tLeft()
mFwdDig()
d = d+1
print(d.. " / "..tunnelLength)
until d == tunnelLength
end
receiveCmd()
tRight()
tDig()
goTo(data.X, data.Y, data.Z)
placeChest()
HERE IS PASTEBIN FOR TURTLE SENDING COMMANDS