Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- CompFlowerV2
- -- Layout
- -- =======
- -- [-] = wall; [x] = grass; [T] = turtle; [p] = piston
- --
- -- top view
- -- [-][-][-][-][-][-][-][-][-]
- -- [-][x][x][x][x][x][x][x][-]
- -- [-][x][x][x][x][x][x][x][-]
- -- [-][x][x][x][x][x][x][x][-]
- -- [-][x][x][x][T][x][x][x][-]
- -- [-][x][x][x][x][x][x][x][-]
- -- [-][x][x][x][x][x][x][x][-]
- -- [-][x][x][x][x][x][x][x][-]
- -- [-][-][-][-][-][-][-][-][-]
- -- side view
- -- [-] [T] [-]
- -- [-] [-]
- -- [p][x][x][x][x][x][x][x] [p]
- -- [-][-][-][-][-][-][-][-][-]
- -- a computer and a monitor to control that also need a chest near the turtle
- -- for coal if the turtle need to move and bone meal + botania bone meal
- --
- -- Basic behaviour
- -- ===============
- -- Init the screen (3 buttons: vanilla bone meal, botania bone meal, stop)
- -- wait for button to be push
- -- send order stop (to stop the current turtle task even if none)
- -- ask if turtle is ready
- -- send the order pushed
- -- back to wait for button push
- --DEBUG
- DEBUG = true
- if DEBUG then
- print("[DEBUG] Start of CompFlowerV2")
- end
- -- Need the button api
- -- button api from Siarko => pastebin get Lcz2CpsY button
- os.loadAPI("button")
- -- modem on the left of the computer
- rednetHostname = "compFlower"
- rednet.open("left")
- rednetProtocol = "flower"
- rednetTimeout = 40 -- sec
- rednet.host(rednetProtocol,rednetHostname)
- tryAck = 0
- tryMax = 5
- -- choosing a hostname for the turtle for easy com
- hostnameTurtle = "turtFlower"
- idTurtle = -1
- if DEBUG then
- print("[DEBUG] rednet => prot : " ..rednetProtocol.."; hostname : "..rednetHostname.." timeout : ",rednetTimeout)
- end
- -- Monitors on the right of the computer (using two monitors for look)
- m = peripheral.wrap("right")
- -- set the monitor for the button api
- button.setMonitor(m)
- -- allBtnsName = every btn name
- allBtnsName = {}
- allBtnsName[1] = "Bone Meal"
- allBtnsName[2] = "Botania"
- allBtnsName[3] = "Stop"
- idBtnStop = 3
- idActiveBtn = idBtnStop
- myButtons = {}
- -- small screen should'nt have more than three
- function InitScreen()
- if DEBUG then
- print("[DEBUG] Start of the function InitScreen")
- end
- -- m to access monitor
- m.clear()
- cptOffsetBtn = 0
- for i,v in pairs(allBtnsName) do
- myButtons[i] = button.create()
- -- button.setText("Value",bool:resize)
- myButtons[i].setText(" "..v.." ",true)
- myButtons[i].setAlign("center")
- myButtons[i].setPos(2,i+cptOffsetBtn)
- myButtons[i].setColor(colors.gray)
- myButtons[i].setBlinkColor(colors.lime)
- myButtons[i].onClickReturn(i)
- cptOffsetBtn = cptOffsetBtn+1
- end
- myButtons[idBtnStop].setColor(colors.lime)
- idActiveBtn = idBtnStop
- end
- function FindTurtleId()
- if DEBUG then
- print("[DEBUG] Start function FindTurtleId")
- end
- local id
- while idTurtle == -1 do
- id = rednet.lookup(rednetProtocol,hostnameTurtle)
- if DEBUG then
- print("[DEBUG] id = ",id)
- end
- if id then
- if DEBUG then
- print("[DEBUG] idTurtle = ",id)
- end
- idTurtle = id
- end
- end
- end
- function StopPlz()
- gotAnswer = false
- while not gotAnswer do
- rednet.send(idTurtle,"stop",rednetProtocol)
- id,msg,p,d = rednet.receive(rednetProtocol,3)
- if msg == true then
- gotAnswer = msg
- end
- end
- end
- function SendOrder(id)
- if DEBUG then
- print("[DEBUG] Start function SendOrder id => ",id)
- end
- if id == -1 then
- return;
- end
- StopPlz()
- if id ~= idBtnStop then
- rednet.send(idTurtle,id,rednetProtocol)
- idC,ack,p,d = rednet.receive(rednetProtocol,rednetTimeout)
- HandleAck(ack,id)
- else
- HandleAck(true,id)
- end
- end
- function HandleAck(ack,id)
- if DEBUG then
- print("[DEBUG] Start function HandleAck ack, id = ",ack,v)
- end
- -- define possible ack
- myButtons[idActiveBtn].setColor(colors.gray)
- if ack then
- myButtons[id].setColor(colors.lime)
- idActiveBtn = id
- else
- -- put everythin on stop state
- myButtons[id].setColor(colors.red)
- idActiveBtn = id
- end
- end
- InitScreen()
- FindTurtleId()
- while true do
- e,v = pcall(button.await,myButtons)
- SendOrder(v or -1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement