Posted 12 November 2012 - 09:21 PM
So i had been trying to make a totally self grid tunnel turtle squad (9 wireless turtles to be exact) and my problem is a logistic part of the code.
The turtles are in this position if you saw then from the back:
1 2 3
4 5 6
7 8 9
1, 3, 7 and 9 dig and place blocks in their 2 respective corners while 2, 4, 6 and 8 only dig their respective side while 5 is the host computer that only digs and goes front,
the problem is that for the sake of some turtles going faster than others, computer 5 reads wireless messages from all of the other computers (taking advantage that this turtle finishes faster) and after all client turtles give their finish message, turtle 5 gives and approval message for the next chain of steps.
Edit:Found out that if i activate the host turtle 1st and then the other turtles they do one step and then the last client turtle that got activated gets stuck.
Logic:
They dig their sides, up and down, and then they place a decorative block-> turtle that finishes sends a message to turtle 5 -> when 5 gets a finish message from all turtles, 5 sends a message to the other turtles to go forward (while turtle.forward ~= true do turtle.dig()) -> "repeat"
My problem is that is seems to lag or get stuck since the turtles do their fist dig and never go forward for the next dig, i dont know what im doing wrong :P/>/>
Host turtle, aka "5":
Base code for the other turtles:
The turtles are in this position if you saw then from the back:
1 2 3
4 5 6
7 8 9
1, 3, 7 and 9 dig and place blocks in their 2 respective corners while 2, 4, 6 and 8 only dig their respective side while 5 is the host computer that only digs and goes front,
the problem is that for the sake of some turtles going faster than others, computer 5 reads wireless messages from all of the other computers (taking advantage that this turtle finishes faster) and after all client turtles give their finish message, turtle 5 gives and approval message for the next chain of steps.
Edit:Found out that if i activate the host turtle 1st and then the other turtles they do one step and then the last client turtle that got activated gets stuck.
Logic:
They dig their sides, up and down, and then they place a decorative block-> turtle that finishes sends a message to turtle 5 -> when 5 gets a finish message from all turtles, 5 sends a message to the other turtles to go forward (while turtle.forward ~= true do turtle.dig()) -> "repeat"
My problem is that is seems to lag or get stuck since the turtles do their fist dig and never go forward for the next dig, i dont know what im doing wrong :P/>/>
Host turtle, aka "5":
local function P5()
T1=0
T2=0
T3=0
T4=0
T6=0
T7=0
T8=0
T9=0
Total=0
Steps=0
term.clear()
term.setCursorPos(1,1)
print(Total)
print("-1")--debug
print(Steps)--debug
while Steps < 64 do
print("-2")
--NOTE: Here is where the code stops responding since print("-3")--debug never is displayed.
local event, param1, param2 = os.pullEvent("rednet_message")
print(param2)
print("-3")--debug
if(param2=="T1OK") then
rednet.send(12,"OK")
T1=1
Total=T1+T2+T3+T4+T6+T7+T8+T9
end
if(param2=="T2OK") then
rednet.send(13,"OK")
T2=1
Total=T1+T2+T3+T4+T6+T7+T8+T9
end
if(param2=="T3OK") then
rednet.send(14,"OK")
T3=1
Total=T1+T2+T3+T4+T6+T7+T8+T9
end
if(param2=="T4OK") then
rednet.send(15,"OK")
T4=1
Total=T1+T2+T3+T4+T6+T7+T8+T9
end
if(param2=="T6OK") then
rednet.send(17,"OK")
T6=1
Total=T1+T2+T3+T4+T6+T7+T8+T9
end
if(param2=="T7OK") then
rednet.send(18,"OK")
T7=1
Total=T1+T2+T3+T4+T6+T7+T8+T9
end
if(param2=="T8OK") then
rednet.send(19,"OK")
T8=1
Total=T1+T2+T3+T4+T6+T7+T8+T9
end
if(param2=="T9OK") then
rednet.send(20,"OK")
T9=1
Total=T1+T2+T3+T4+T6+T7+T8+T9
end
term.clear()
term.setCursorPos(1,1)
print(Total)
print("-4")--debug
if(Total>=8) then
rednet.send(12,"Next")
sleep(0.1)
rednet.send(13,"Next")
sleep(0.1)
rednet.send(14,"Next")
sleep(0.1)
rednet.send(15,"Next")
sleep(0.1)
--rednet.send(16,"Next")
rednet.send(17,"Next")
sleep(0.1)
rednet.send(18,"Next")
sleep(0.1)
rednet.send(19,"Next")
sleep(0.1)
rednet.send(20,"Next")
while turtle.forward()==false do
turtle.dig()
end
Steps=Steps+1
Total=0
T1=0
T2=0
T3=0
T4=0
T6=0
T7=0
T8=0
T9=0
end
sleep(0)
end
turtle.turnLeft()
turtle.turnLeft()
end
Base code for the other turtles:
local function P1()
turtle.select(1)
while Steps<64 do
--Detect and place up
while turtle.placeUp() ~= true do
turtle.digUp()
sleep(1)
end
Placecount=Placecount+1
if(Placecount>=64) then
Slot=Slot+1
Placecount=0
turtle.select(Slot)
end
--Detect and place up
--Detect and place left
turtle.turnLeft()
while turtle.place() ~= true do
turtle.dig()
sleep(1)
end
Placecount=Placecount+1
if(Placecount>=64) then
Slot=Slot+1
Placecount=0
turtle.select(Slot)
end
turtle.turnRight()
--Detect and place left
--Wireless
Lock=0
Lock2=0
while Lock==0 do
if Lock2~=1 then
rednet.send(T5ID,"T1OK")
term.clear()
term.setCursorPos(1,1)
print("T1OK")
end
local event, param1, param2 = os.pullEvent("rednet_message")
if(param2=="OK") then
Lock2=1
print(param2)
end
if(param2=="Next") then
Lock=1
end
sleep(0)
end
Lock=0
Lock2=0
--Wireless
if(Steps<63) then
while turtle.forward()== false do
turtle.dig()
end
end
Steps=Steps+1
end
turtle.turnLeft()
turtle.turnLeft()
end