Posted 28 May 2015 - 10:39 AM
Hi,
I try to make a conversation between my computer and some turtles. So, the computer will broadcast world coordinates and turtles will ask for authorization to go mining there (avoiding many turtles to go to the same place).
But for some reason, the confirmation message won't send to the turtle. I checked the senderID and the protocol used and same for receive and everything is correct…
Here's the computer code (I removed the mining algorithm to help focus on the rednet problem) :
And the mining turtle rednet part :
I try to make a conversation between my computer and some turtles. So, the computer will broadcast world coordinates and turtles will ask for authorization to go mining there (avoiding many turtles to go to the same place).
But for some reason, the confirmation message won't send to the turtle. I checked the senderID and the protocol used and same for receive and everything is correct…
Here's the computer code (I removed the mining algorithm to help focus on the rednet problem) :
rednet.open("top")
PROTOCOL = "MiningNetwork"
--# Mining position algorithm
while #list_position > 0 do
--# Get world coordinate
tempTable = list_position[#list_position]
x = tempTable[1]
y = tempTable[2]
z = tempTable[3]
--# Broadcast x and z world coordinates
rednet.broadcast("x:"..string.format("%5d",x).."z:"..string.format("%5d",z),PROTOCOL)
--# Receive a message asking for authorization
local senderID,message,PROTOCOLReceive = rednet.receive(5)
--# Verify the message
if message:sub(3,7)==x and message:sub(16,22)=="will go"then
rednet.send(senderID, "Ok", PROTOCOL)
table.remove(list_position)
end
end
And the mining turtle rednet part :
local Mining = false
rednet.open("right")
while Mining == false do
--# Wait to receive a message from the server
local senderID, message, protocol = rednet.receive()
if message:sub(1,2) == "x:" then
--# Ask for authorization
rednet.send(senderID, "x:"..message:sub(3,7).."Z:"..message:sub(10,14).." will go", protocol)
--# Wait for authorization
local senderIDConfirm, messageConfirm, protocolConfirm = rednet.receive(20)
if messageConfirm == "Ok" then
shell.run("goto",message:sub(3,7),y,message:sub(10,14))
Mining = true
end
end
end