Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --not my code
- function split(pString, pPattern)
- local Table = {} -- NOTE: use {n = 0} in Lua-5.0
- local fpat = "(.-)" .. pPattern
- local last_end = 1
- local s, e, cap = pString:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(Table,cap)
- end
- last_end = e+1
- s, e, cap = pString:find(fpat, last_end)
- end
- if last_end <= #pString then
- cap = pString:sub(last_end)
- table.insert(Table, cap)
- end
- return Table
- end
- --not my code
- --now my code VVV
- local modem = peripheral.find("modem")
- local treesgrown = {}
- local turtledocked = peripheral.isPresent("left")
- local function parseName()
- return split(os.getComputerLabel(),"_")[3]
- end
- local id = parseName()
- local function activateTurtle(pos,bypass)
- if not turtledocked and not bypass then return end
- turtledocked = false
- modem.transmit(tonumber(id)+200,tonumber(id)+200,pos)
- print("Turtle has departed.")
- end
- modem.open(40)
- term.clear()
- term.setCursorPos(1,1)
- print("Listening for Tree Events.")
- while true do
- local e,side,channel,repchannel,msg,distance = os.pullEvent()
- if e == "modem_message" then
- print("MSG RECEIVED C:",channel,"R:",msg.Reason,"P:",msg.Pos)
- if channel == id*10+30 and msg.Reason == "TreeGrew" then
- if turtledocked and #treesgrown == 0 then
- activateTurtle(msg.Pos)
- else
- table.insert(treesgrown,msg.Pos)
- end
- end
- elseif e == "peripheral" then
- if peripheral.isPresent("left") then
- print("Turtle has Docked.")
- if #treesgrown > 0 then
- print(#treesgrown,"trees currently grown")
- print(treesgrown[1])
- activateTurtle(treesgrown[1],true)
- table.remove(treesgrown,1)
- else
- turtledocked = true
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment