Need help with computercraft!

  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

HighDangerr

New Member
Jul 29, 2019
6
0
0
I have a problem.

I want to use computercraft with mystcraft to set portals.
but i get a error from the books code.

  1. local data = {}
  2. rednet.open("right")
  3. p = peripheral.wrap("bottom")

  4. function clearInv()
  5. for i = 1,16 do
  6. turtle.select(i)
  7. turtle.dropDown()
  8. end
  9. end

  10. function checkSlots(id)
  11. data = {}
  12. local slot
  13. local name
  14. local slots = p.getAllStacks()
  15. for i,j in pairs(slots) do
  16. slot = i
  17. name = j["destination"]
  18. -- print(name)
  19. data[slot]=name
  20. end
  21. rednet.send(id,"done")
  22. end

  23. function removeSlot(slot)
  24. p.pushItem("up", slot, 1)
  25. rs.setOutput("left", true)
  26. sleep(1)
  27. rs.setOutput("left", false)
  28. end

  29. function book(slot,id)
  30. p.pushItem("up", slot, 1)
  31. turtle.select(1)
  32. turtle.drop()
  33. sleep(5)
  34. getBook()
  35. turtle.select(1)
  36. turtle.dropDown()
  37. rednet.send(tonumber(id), "done")
  38. end

  39. function getBook()
  40. turtle.suck()
  41. end

  42. function getNames(id)
  43. local nameTbl = textutils.serialize(data)
  44. rednet.send(tonumber(id), nameTbl)
  45. end

  46. clearInv()

  47. while true do
  48. local id, msg, dis = rednet.receive()
  49. local newmsg = string.match(msg, "%a+")
  50. -- print(msg)
  51. if newmsg == "checkSlots" then
  52. checkSlots(id)
  53. elseif newmsg == "getNames" then
  54. getNames(id)
  55. elseif newmsg == "remove" then
  56. removeSlot(tonumber(string.match(msg, "%d+")))
  57. rednet.send(id,"done")
  58. elseif newmsg == "books" then
  59. slot = string.match(msg, "%d+")
  60. book(tonumber(slot), id)
  61. end
  62. end

this is the code. and it says line 16 is attempt to call nil! can anyone help me please?
 

Democretes

New Member
Jul 29, 2019
1,134
0
1
First of all the getBook() function doesn't need to exist. You call it once and use it to replace a turtle.suck().

What peripheral are you wrapping btw? You're calling p.getAllStacks() and I"m pretty sure that's not even a thing.
 

HighDangerr

New Member
Jul 29, 2019
6
0
0
i am trying to get the books in the book receptacle. And this was a code what i found on the internet ;)
 

Democretes

New Member
Jul 29, 2019
1,134
0
1
Figure out what peripheral they were wrapping. That'll probably do most of the work for you.
 

SkyBoy96

New Member
Jul 29, 2019
100
0
0
I think the getAllStacks function will include empty slots, giving you nil values. You will need to do something like this (example code, functions may be different)
Code:
slots=chest.getmaxInventorySize()
for i=1,slots do
  item = chest.getStackInSlot(i)
  --Do stuffs with the item here
end