Stravides

turtlereceive v1.0.0

Dec 6th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.65 KB | None | 0 0
  1. rednet.open("left")
  2.     turtleslots= {}
  3.    
  4. function split(str, delim, maxNb)  
  5.   if string.find(str, delim) == nil then
  6.     return { str }
  7.   end
  8.   if maxNb == nil or maxNb <1 then
  9.     maxNb = 0
  10.   end
  11.   local result = {}
  12.   local pat = "(.-)"..delim.."()"
  13.   local nb = 0
  14.   local lastPos
  15.   for part, pos in string.gmatch(str,pat) do
  16.     nb = nb+1
  17.     result[nb]=part
  18.     lastPos=pos
  19.     if nb==maxNb then break end
  20.   end
  21.   if nb ~= maxNb then
  22.     result[nb+1] = string.sub(str,lastPos)
  23.   end
  24.   return result
  25. end
  26.  
  27.  
  28. function turtleSlots(ID,slot)
  29.     turtleslots[ID]= {}
  30.     turtleslots[ID]["slot"]=slot
  31. end
  32.      
  33. function fillSlotsData()
  34.   turtleSlots("A1","1")
  35.   turtleSlots("A2","2")
  36.   turtleSlots("A3","3")
  37.   turtleSlots("A4","4")
  38.  
  39.   turtleSlots("B1","5")
  40.   turtleSlots("B2","6")
  41.   turtleSlots("B3","7")
  42.   turtleSlots("B4","8")
  43.  
  44.   turtleSlots("C1","9")
  45.   turtleSlots("C2","10")
  46.   turtleSlots("C3","11")
  47.   turtleSlots("C4","12")
  48.  
  49.   turtleSlots("D1","13")
  50.   turtleSlots("D2","14")
  51.   turtleSlots("D3","15")
  52. end
  53.  
  54. function replaceJuice()
  55.    rs.setOutput("back",true)  -- Stop the autonomous activator spitting out the bucket
  56.    turtle.select(tonumber(Tslot))
  57.    print("Slot selected:"..tonumber(Tslot))
  58.    turtle.drop()
  59.    print("Placed liquid in automn:")
  60.    sleep(3)
  61.    rs.setOutput("back",false)  -- Make the autonomous activator spit out the bucket
  62. end
  63.  
  64. fillSlotsData()
  65.  
  66. while true do
  67.   print("started")
  68.   local event, id, msg = os.pullEvent("rednet_message")
  69.   local Tab = split(msg,"|",2)
  70.   Tslot=turtleslots[Tab[1]]["slot"]
  71.   print("Message received:"..msg)
  72.   print("Slot "..Tslot.." has been chosen")
  73.   replaceJuice()
  74. end
Advertisement
Add Comment
Please, Sign In to add comment