Advertisement
VaMinion

Reactor Disk Query

Jan 27th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.56 KB | None | 0 0
  1. -- Uses ender chests and floppy disks to transfer data across dimensions.
  2. -- This program queries the reactor, writes active status, stored energy, current fuel amount, max fuel, and waste to a floppy.
  3. -- Then the floppy is moved into an ender chest to be read by the querying system.
  4.  
  5. -- Placement:
  6. --  1. Back of turtle to reactor's ComputerCraft interface.
  7. --  2. Enderchest in front of the turtle.
  8. --  3. Disk drive on top of turtle
  9.  
  10. -- Define whose reactor this is for. This will allow multiple reactor checks to share a disk if necessary.
  11. reactor_name = "rungok_moon"
  12.  
  13. -- Wrap the reactor now.
  14. reactor = peripheral.wrap("back")
  15.  
  16. -- Define reactor stats variable.
  17. -- Yes, it's a global variable. Dealwithit.jpg
  18.  t_reactor_stats = {
  19.    ["energyStored"] = 0,
  20.    ["fuelAmount"] = 0,
  21.    ["fuelMax"] = 0,
  22.    ["active"] = 0,
  23.    ["waste"] = 0
  24.  }
  25.  
  26. function disk_to_chest()
  27.  print("Pulling disk from drive.")
  28.  turtle.suckUp()
  29.  print("Putting disk in ender chest.")
  30.  turtle.drop()
  31. end
  32.  
  33. function disk_to_drive()
  34.  print("Pulling disk from ender chest.")
  35.  -- If we try to pull the disk and the job fails, sleep 1 second before trying again.
  36.  while not turtle.suck() do
  37.   print("Disk pull failed; sleeping for 1 second.")
  38.   os.sleep(1)
  39.  end
  40.  print("Putting disk into drive.")
  41.  turtle.dropUp()
  42. end
  43.  
  44. function pull_reactor_stats()
  45.  t_reactor_stats["active"] = reactor.getActive()
  46.  t_reactor_stats["energyStored"] = reactor.getEnergyStored()
  47.  t_reactor_stats["fuelAmount"] = reactor.getFuelAmount()
  48.  t_reactor_stats["fuelMax"] = reactor.getFuelAmountMax()
  49.  t_reactor_stats["waste"] = reactor.getWasteAmount()
  50.  -- Print results
  51.  -- for key,value in pairs(t_reactor_stats) do print(key,value) end
  52. end
  53.  
  54. function main()
  55.  -- First, we run a job to pull the disk from the drive and put it into the ender chest, just in case things rebooted mid-run.
  56.  -- This will put the disk in the chest even if it is in the turtle's inventory.
  57.  disk_to_chest()
  58.  
  59.  -- Now we begin the procedure.
  60.  while true do
  61.   -- First, load the disk into the drive.
  62.   disk_to_drive()
  63.  
  64.   -- Populate the table with the reactor's current stats
  65.   pull_reactor_stats()
  66.  
  67.   -- Write the results to the disk
  68.   print("Writing reactor stats to disk...")
  69.   reactor_dump = fs.open("/disk/"..reactor_name, "w")
  70.   reactor_dump.write(textutils.serialize(t_reactor_stats))
  71.   reactor_dump.close()
  72.  
  73.   -- Move the disk back to the ender chest
  74.   disk_to_chest()
  75.  
  76.   -- Sleep for 60 seconds to save computing cycles and give other systems a chance to query.
  77.   print("Sleeping...")
  78.   os.sleep(60)
  79.  end
  80. end
  81.  
  82. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement