Advertisement
Guest User

foxHunt

a guest
Nov 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.97 KB | None | 0 0
  1. modem = peripheral.wrap("back")
  2. sniffer = peripheral.wrap("top")
  3.  
  4. modem.open(2)
  5. foxLoci = {}
  6. function getFoxes()
  7.   print("getting Foxes ...")
  8.   b = fs.open("location","r")
  9.   locus = b.readLine()
  10.   b.close()
  11.   nearest = textutils.serialise(sniffer.getNearbyPlayers())
  12.   b = fs.open("infos","w")
  13.   b.write(locus .. nearest .. "\n")
  14.   modem.transmit(1,2,"foxHunt")
  15.   foxLoci[1] = locus .. nearest  
  16.   sep = string.find(foxLoci[1],"{")
  17.   myLocus = textutils.unserialise("{" .. string.sub(foxLoci[1],1,sep-1) .. "}")
  18.   rest = string.sub(foxLoci[1],sep)
  19.  
  20.   print("Locus is ")
  21.   print(myLocus)
  22.   print(" and rest is " .. rest)
  23.   j = textutils.unserialise(rest)
  24.   print(type(j))
  25.   print(#j)
  26.   for i=1,3 do
  27.     event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  28.     print("recieving message " .. message)
  29.     foxLoci[i + 1] = message
  30.     b.write(message .. "\n")
  31.     b.flush()
  32.    
  33.   end
  34.   b.close()
  35. end
  36.  
  37. getFoxes()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement