Advertisement
HandieAndy

station.lua

Sep 8th, 2023 (edited)
1,157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.98 KB | None | 0 0
  1. --[[
  2. Stations are kiosks where users can configure their portable computer for a
  3. particular route to another station.
  4.  
  5. You should add a "station_config.tbl" file containing:
  6. {
  7.     name = "stationname",
  8.     displayName = "Station Name",
  9.     range = 8
  10. }
  11. ]]--
  12.  
  13. local modem = peripheral.wrap("top") or error("Missing top modem")
  14. local BROADCAST_CHANNEL = 45451
  15.  
  16. local function readConfig()
  17.     local f = io.open("station_config.tbl", "r")
  18.     if not f then error("Missing station_config.tbl") end
  19.     local cfg = textutils.unserialize(f:read("*a"))
  20.     f:close()
  21.     return cfg
  22. end
  23.  
  24. local function broadcast(config)
  25.     while true do
  26.         modem.transmit(BROADCAST_CHANNEL, BROADCAST_CHANNEL, config)
  27.         os.sleep(1)
  28.     end
  29. end
  30.  
  31. local config = readConfig()
  32. term.clear()
  33. term.setCursorPos(1, 1)
  34. print("Running station transponder for \""..config.name.."\".")
  35. print("  Display Name: "..config.displayName)
  36. print("  Range: "..config.range.." blocks")
  37. broadcast(config)
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement