Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- TurtFlowerV2
- -- Basic behaviour
- -- ================
- -- try to find idComp
- -- wait for order
- -- when get order use bone meal if empty grab from chest on top
- -- if it's good use it bellow and send "good" ack
- -- if not send "notgood" ack
- -- then wait for other order
- -- DEBUG
- DEBUG = true
- if DEBUG then
- print("[DEBUG] Start of CompFlowerV2")
- end
- hostnameComp = "compFlower"
- hostnameCmd = "cmdFlower"
- idComp = -1
- idCmd = -1
- -- modem on the right of the turtle
- rednetHostname = "turtFlower"
- rednet.open("right")
- rednetProtocol = "flower"
- rednet.host(rednetProtocol,rednetHostname)
- idStop = 3
- if DEBUG then
- print("[DEBUG] rednet => prot : " ..rednetProtocol.."; hostname : "..rednetHostname)
- end
- function FindCompId()
- if DEBUG then
- print("[DEBUG] Start function FindCompId")
- end
- local id
- while idComp == -1 do
- id = rednet.lookup(rednetProtocol,hostnameComp)
- if id then
- if DEBUG then
- print("[DEBUG] idComp = ",id)
- end
- idComp = id
- end
- end
- end
- function FindCmdId()
- if DEBUG then
- print("[DEBUG] Start function FindCmdId")
- end
- local id
- while idCmd == -1 do
- id = rednet.lookup(rednetProtocol,hostnameCmd)
- if id then
- if DEBUG then
- print("[DEBUG] idCmd = ",id)
- end
- idCmd = id
- end
- end
- end
- function ExecuteOrder(id)
- gotStop = false
- if DEBUG then
- print("[DEBUG] Start of ExecuteOrder id = ",id)
- end
- if id == -1 or id == idStop or id == "stop" then
- SendAck(true)
- return
- end
- turtle.select(id)
- turtle.suckUp()
- if turtle.getItemCount() > 0 then
- SendAck(true)
- else
- SendAck(false)
- return
- end
- while not gotStop do
- turtle.placeDown()
- rednet.send(idCmd,true,rednetProtocol)
- turtle.suckUp()
- id,msg,p,d = rednet.receive(rednetProtocol,1)
- if msg == "stop" then
- gotStop = true
- SendAck(true)
- end
- end
- end
- function SendAck(ack)
- if DEBUG then
- print("[DEBUG] Start of SendAck ack = "..ack)
- end
- rednet.send(idComp,ack,rednetProtocol)
- end
- FindCompId()
- FindCmdId()
- while true do
- id,msg,d,p = rednet.receive(rednetProtocol)
- ExecuteOrder(msg or -1)
- end
Advertisement
Add Comment
Please, Sign In to add comment