SHARE
TWEET

advanced_redstone.lua

a guest Sep 17th, 2019 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require("component")
  2. local computer = require("computer")
  3. local serialization = require("serialization")
  4.  
  5. -- local r = component.proxy(component.list("redstone")())
  6. local m = component.proxy(component.list("modem")())
  7.  
  8. local own_name = "fc_rice"
  9.  
  10. m.open(102)
  11.  
  12. function isInt(n)
  13.   return type(n) == "number" and math.floor(n) == n
  14. end
  15.  
  16. function validateSide(side)
  17.   return is_int(side) and side > -1 and side < 6
  18. end
  19.  
  20. function validateStrenght(strength)
  21.   return is_int(strength) and strength > -1
  22. end
  23.  
  24. function checkName(instruction)
  25.   return (instruction.name ~= nil and (instruction.name == "*" or instruction.name == own_name))
  26. end
  27.  
  28. function parseInstruction(instruction)
  29.   if (not checkName(instruction)) then return end
  30.   print("Message is for me")
  31. end
  32.  
  33. while true do
  34.   local signal_type, localAddress, remoteAddress, port, distance, instruction = computer.pullSignal()
  35.   if (signal_type == "modem_message") then
  36.     print(signal_type)
  37.     if (instruction ~= nil) then
  38.       instruction = serialization.unserialize(instruction)
  39.       print("Hey")
  40.       print(instruction)
  41.       print(instruction.name)
  42.       if (type(instruction) == "table") then
  43.         parseInstruction(instruction)
  44.       end
  45.     end
  46.   end
  47. --  if is_int(side) and is_int(mode) and side > -1 and side < 6 and mode > -1 and mode < 2 then
  48. --    r.setOutput(side, mode)
  49. --  end
  50. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top