Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local turtleId
- local isWirelessTurtle
- local messageOutputFileName
- isWirelessTurtle = peripheral.isPresent("right")
- if (isWirelessTurtle == true) then
- turtleId = os.getComputerLabel()
- rednet.open("right")
- end
- function writeMessage(message)
- print(message)
- -- If this turtle has a modem, then write the message to red net
- if (isWirelessTurtle == true) then
- if (turtleId == nil) then
- rednet.broadcast(message)
- else
- -- Broadcast the message (prefixed with the turtle's id)
- rednet.broadcast("[".. turtleId.."] "..message)
- end
- end
- if (messageOutputFileName ~= nil) then
- -- Open file, write message and close file (flush doesn't seem to work!)
- local outputFile = io.open(messageOutputFileName, "a")
- outputFile:write(message)
- outputFile:write("\n")
- outputFile:close()
- end
- end
- while true do
- if turtle.attack()
- then writeMessage("Mob Detected and Dispatched")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment