Advertisement
UNOBTANIUM

AlvearyComputer

Jun 13th, 2013
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.95 KB | None | 0 0
  1. local beeType = ""
  2. local alvearyNumber = 0
  3. local mode = "not running"
  4.  
  5. if redstone.getOutput("back") then
  6.  mode = "running"
  7. end
  8.  
  9. rednet.open("bottom")
  10.  
  11. function saveVar()
  12.  local file = fs.open("beeSystemVariables","w")
  13.   file.writeLine(beeType)
  14.   file.writeLine(alvearyNumber)
  15.  file.close()
  16. end
  17.  
  18. function loadVar()
  19.  if not fs.exists("beeSystemVariables") then setVar() return end
  20.  local file = fs.open("beeSystemVariables","r")
  21.   beeType = file.readLine()
  22.   alvearyNumber = tonumber(file.readLine())
  23.  file.close()
  24. end
  25.  
  26. function setVar()
  27.  clear()
  28.  local input = ""
  29.  while input == "" do
  30.   print("Which type of bee is in the alveary?")
  31.   print("Hit Enter to set the name!")
  32.   input = read()
  33.  end
  34.  beeType = input
  35.  input = 0
  36.  while input <= 0 or input > 10 do
  37.   clear()
  38.   print("Enter a number between 1 and 10!")
  39.   print("This is used to shutdown this alveary individually if you are having multiple " .. beeType .. " running in different alvearies.")
  40.   input = tonumber(read())
  41.  end
  42.  alvearyNumber = input
  43.  saveVar()
  44. end
  45.  
  46. function clear()
  47.  term.clear()
  48.  term.setCursorPos(1,1)
  49. end
  50.  
  51. function changeMode(newState)
  52.  for k,v in pairs(redstone.getSides()) do
  53.   redstone.setOutput(v, newState)
  54.  end
  55.  if redstone.getOutput("back") then
  56.   mode = "running"
  57.  else
  58.   mode = "not running"
  59.  end
  60.  saveVar()
  61. end
  62.  
  63. function run()
  64.  clear()
  65.  print("Bee Type: " .. beeType)
  66.  print("Type Number: " .. alvearyNumber)
  67.  term.write("This alveary is " .. mode)
  68.  
  69.  local event = { os.pullEvent() }
  70.  if event[1] == "key" then
  71.   setVar()
  72.  elseif event[1] == "rednet_message" then
  73.   local m = textutils.unserialize(event[3])
  74.   if type(m[1]) == "string" and type(m[2]) == "string" and type(m[3]) == "number" then
  75.    if m[2] == beeType and m[3] == alvearyNumber then
  76.     if m[1] == "TurnOn" then
  77.      changeMode(true)
  78.     elseif m[1] == "TurnOff" then
  79.      changeMode(false)
  80.     end
  81.    end
  82.   end
  83.  end
  84. end
  85.  
  86.  
  87. loadVar()
  88. while true do
  89.  run()
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement