Advertisement
Guest User

startup

a guest
Jul 20th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.03 KB | None | 0 0
  1. -- variables
  2.  
  3. local camera
  4. local modem
  5.  
  6. for _, name in ipairs(peripheral.getNames()) do
  7.  
  8.   if (peripheral.getType(name) == "warpdriveLaserCamera") then
  9.     camera = peripheral.wrap(name)
  10.   end
  11.  
  12.   if (peripheral.getType(name) == "modem") then
  13.     modem = peripheral.wrap(name)
  14.   end
  15. end
  16.  
  17. assert(not (camera == nil))
  18. assert(not (modem == nil))
  19.  
  20. -- setup
  21.  
  22. camera.beamFrequency(1420)
  23. camera.videoChannel(66)
  24.  
  25. -- callBacks
  26.  
  27. function callBack()
  28.  
  29.   type, x_, y_, z_, id, meta, res = camera.getScanResult()
  30.  
  31.   if res ~= -1 then    
  32.     target = textutils.serialize( { x = x_, y = y_, z = z_ } )
  33.     print("Targeting "..target)
  34.    
  35.     modem.transmit(3, 1, target)
  36.   end
  37.  
  38. end
  39.  
  40. -- loop
  41.  
  42. local loop = true
  43. local interval = 0.1
  44.  
  45. local timer = os.startTimer(0)
  46.  
  47. while loop do
  48.   local event, arg1, arg2, arg3, arg4 = os.pullEvent()
  49.  
  50.   if (event == "timer") then
  51.     callBack()
  52.     os.startTimer(interval)
  53.   end
  54.  
  55.   if (event == "key") then
  56.     if (arg1  == keys.space) then
  57.       break
  58.     end
  59.   end
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement