Advertisement
Timendainum

Untitled

Dec 3rd, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | None | 0 0
  1. -- cow control program
  2. local server = "cowsensor2"
  3. local side = "top"
  4. local cowSensor = nperi.wrap(server, side)
  5. local cows = {}
  6.  
  7. local function updateCows()
  8.     local tResults = cowSensor.getTargets()
  9.     if tResult ~= nil then
  10.         cows = {}
  11.         for k,v in pairs do
  12.             if type(k) == "string" and string.len(k) > 3 and string.sub(k, 1, 3) == "Cow" then
  13.                 cows[k] = v
  14.             end
  15.         end
  16.     else
  17.         print("Unable to update cows, sensor result nil.")
  18.     end
  19. end
  20.  
  21. local function countCows()
  22.     if cows == nil then
  23.         return 0
  24.     else
  25.         local result = 0
  26.         for k,v in pairs(cows) do
  27.             result = result + 1
  28.         end
  29.         return result
  30.     end
  31. end
  32.  
  33. ------------------------------------------
  34. --
  35. --
  36. --[[
  37. txt.sPrint("IsPresent: ", nperi.isPresent(server, side))
  38. local p = nperi.wrap(server, side)
  39. txt.sPrint("Wrap: ", p)
  40. local tm = nperi.getMethods(server, side)
  41. if tm ~= nil then
  42.     textutils.tabulate(tm)
  43. else
  44.     print("getMethods nil")
  45. end
  46.  
  47. local tt = p.getTargets()
  48.  
  49. txt.sPrint(tt)
  50.  
  51. if tt ~= nil then
  52.     print(serial.serialize(tt))
  53. else
  54.     print("getMethods nil")
  55. end
  56.  
  57.  
  58.  
  59.  
  60. while true do
  61.     updateCows()
  62.     txt.sPrint("There are ", countCows(), " cows in the farm.")
  63. end
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. -- test
  71. txt.sPrint("IsPresent: ", peripheral.isPresent("top"))
  72. local p = sensor.wrap("top")
  73. txt.sPrint("Wrap: ", p)
  74. local tm = peripheral.getMethods("top")
  75. if tm ~= nil then
  76.     textutils.tabulate(tm)
  77. else
  78.     print("getMethods nil")
  79. end
  80.  
  81. local tt = p.getTargets()
  82.  
  83. txt.sPrint(tt)
  84.  
  85. if tt ~= nil then
  86.     print(serial.serialize(tt))
  87. else
  88.     print("getMethods nil")
  89. end
  90. ]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement