View difference between Paste ID: jKwaxW4z and 4JtaN2eZ
SHOW: | | - or go back to the newest paste.
1
local data = {}
2
rednet.open("right")
3
p = peripheral.wrap("bottom")
4
5
function checkSlots(id)
6
   data = {}
7
   local slot
8
   local name
9
   local slots = p.getAllStacks()
10
   for i,j in pairs(slots) do
11
      slot = i
12-
      name = j["destination"]
12+
      name = j.all()["myst_book"]["destination"]
13
--      print(name)
14
      data[slot]=name
15
   end
16
   rednet.send(id,"done")
17
end
18
19
function removeSlot(slot)
20
   p.pushItem("up", slot, 1)
21
   rs.setOutput("left", true)
22
   sleep(1)
23
   rs.setOutput("left", false)
24
end
25
26
function book(slot,id)
27
   p.pushItem("up", slot, 1)
28
   turtle.select(1)
29
   turtle.drop()
30
   sleep(5)
31
   getBook()
32
   turtle.select(1)
33
   turtle.dropDown()
34
   rednet.send(tonumber(id), "done")
35
end
36
37
function getBook()
38
   turtle.suck()
39
end
40
41
function getNames(id)
42
   local nameTbl = textutils.serialize(data)
43
   rednet.send(tonumber(id), nameTbl)
44
end
45
46
while true do
47
   local id, msg, dis = rednet.receive()
48
   local newmsg = string.match(msg, "%a+")
49
--   print(msg)
50
   if newmsg == "checkSlots" then
51
     checkSlots(id) 
52
   elseif newmsg == "getNames" then
53
     getNames(id)
54
   elseif newmsg == "remove" then
55
     removeSlot(tonumber(string.match(msg, "%d+")))
56
     rednet.send(id,"done")
57
   elseif newmsg == "books" then
58
     slot = string.match(msg, "%d+")
59
     book(tonumber(slot), id)
60
   end
61
end