Advertisement
osmarks

simple spatial controller

May 11th, 2020
1,037
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.76 KB | None | 0 0
  1. local m = peripheral.find "modem"
  2. local ioside = "bottom"
  3. local io = peripheral.wrap(ioside)
  4. local channel = 15216
  5. local energy = 1.97e6
  6. m.open(channel)
  7.  
  8. local function attempt_swap()
  9.     if not io.getItemMeta(1) then return false, "no cell" end
  10.     if io.getNetworkEnergyStored() < energy then return false, "insufficient energy" end
  11.     rs.setOutput(ioside, true)
  12.     sleep(0.2)
  13.     rs.setOutput(ioside, false)
  14.     return true
  15. end
  16.  
  17. while true do
  18.     local _, _, c, rc, msg = os.pullEvent "modem_message"
  19.     if type(msg) == "table" and msg[1] == "swap" then
  20.         local ok, err = attempt_swap()
  21.         print("SWAP", ok, err)
  22.         m.transmit(channel, channel, {"swapped", ok, err})
  23.     elseif type(msg) == "table" and msg[1] == "ping" then
  24.         m.transmit(channel, channel, {"pong"})
  25.     end
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement