neuroticfox

DraCon 8 (Recommended)

Jul 26th, 2021 (edited)
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.53 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local term = require("term")
  4. local gpu = component.gpu
  5. local screen = component.screen
  6.  
  7.  -- DynamicRes
  8.  
  9. local ratioX, ratioY = screen.getAspectRatio()
  10. local maxX, maxY = gpu.maxResolution()
  11. gpu.setResolution(math.min(ratioX*55, maxX), math.min(ratioY*25,maxY))
  12.  
  13.  -- Safety Checks
  14.  
  15. if not component.isAvailable("draconic_reactor") then
  16.   print("Reactor not connected. Please connect computer to reactor with an Adapter block.")
  17.   os.exit()
  18. end
  19. reactor = component.draconic_reactor
  20. local flux_gates = {}
  21. for x,y in pairs(component.list("flux_gate")) do
  22.   flux_gates[#flux_gates+1] = x
  23. end
  24. if #flux_gates < 2 then
  25.   print("Not enough flux gates connected; please connect inflow and outflow flux gates with Adapter blocks.")
  26.   os.exit()
  27. end
  28. flux_in = component.proxy(flux_gates[1])
  29. flux_out = component.proxy(flux_gates[2])
  30. if not flux_in or not flux_out then
  31.   print("Not enough flux gates connected; please connect inflow and outflow flux gates with Adapter blocks.")
  32.   os.exit()
  33. end
  34.  
  35.  -- Functions
  36.  
  37. function exit_msg(msg)
  38.   term.clear()
  39.   print(msg)
  40.   os.exit()
  41. end
  42.  
  43. function modify_temp(offset)
  44.   local new_temp = ideal_temp + offset
  45.   if new_temp > 8000 then
  46.     new_temp = 8000
  47.   elseif new_temp < 2000 then
  48.     new_temp = 2000
  49.   end
  50.   ideal_temp = new_temp
  51. end
  52.  
  53. local bypassfield = 0
  54. local chaosmode = 0
  55.  
  56. function modify_field(offset)
  57.   local new_strength = ideal_strength + offset
  58.   if new_strength > 100 then
  59.     new_strength = 100
  60.   elseif new_strength < 75 and chaosmode == 1 then
  61.     new_strength = 75
  62.   elseif new_strength < 1 and bypassfield == 0 then
  63.     new_strength = 1
  64.   elseif new_strength < 0.1 and bypassfield == 1 then
  65.     new_strength = 0.1
  66.   end
  67.   ideal_strength = new_strength
  68. end
  69.  
  70.  -- Buttons
  71.  
  72. local adj_button_width = 19
  73. local temp_adjust_x_offset = 68
  74. local temp_adjust_y_offset = 2
  75. local field_adjust_x_offset = temp_adjust_x_offset + adj_button_width + 2
  76. local field_adjust_y_offset = 2
  77. local status = "PeFi"
  78. local lowest_field = 100
  79. local lowest_fuel = 100
  80. local highest_temp = 0
  81. local highest_sat = 0
  82. local highest_outflow = 0
  83. local cutoff_field = 0.75
  84.  
  85.       -- Inflow PID
  86. local proportional_field_error = 0
  87. local inflow_I_sum = 0
  88. local integral_field_error = 0
  89. local derivative_field_error = 0
  90. local inflow_D_last = 0
  91. local inflow_correction = 0
  92.  
  93.     -- Outflow PID
  94. local proportional_temp_error = 0
  95. local outflow_I_sum = 0
  96. local integral_temp_error = 0
  97. local derivative_temp_error = 0
  98. local outflow_D_last = 0
  99. local outflow_correction = 0
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108. local buttons = {
  109.   start={
  110.     x=2,
  111.     y=30,
  112.     width=18,
  113.     height=1,
  114.     text="Start",
  115.     action=function()
  116.       if safe then
  117.         state = "Charging"
  118.         reactor.chargeReactor()
  119.       elseif shutting_down then
  120.         state = "Active"
  121.         reactor.activateReactor()
  122.       end
  123.     end,
  124.     condition=function() return safe or shutting_down end
  125.   },
  126.   shutdown={
  127.     x=2,
  128.     y=30,
  129.     width=18,
  130.     height=1,
  131.     text="Shutdown",
  132.     action=function()
  133.     cutoff_temp = 8001
  134.     ideal_temp = 8000
  135.     ideal_strength = 15
  136.     cutoff_field = 0.75
  137.       state = "Manual Shutdown"
  138.       reactor.stopReactor()
  139.     end,
  140.     condition=function() return running end
  141.   },
  142.       chaosmode={
  143.     x=2,
  144.     y=32,
  145.     width=18,
  146.     height=1,
  147.     text=" Chaos Mode",
  148.     action=function()
  149.       cutoff_temp = 19750
  150.       cutoff_field = 12.5
  151.       ideal_strength = 75
  152.       ideal_temp = 69420
  153.       lowest_field = 100
  154.       chaosmode = 1
  155.     end,
  156.     condition=function() return running end
  157.   },
  158.     analytics={
  159.     x=42,
  160.     y=30,
  161.     width=18,
  162.     height=1,
  163.     text="Reset Analytics",
  164.     action=function()
  165.       highest_temp = 0
  166.       lowest_field = 200
  167.       highest_outflow = 0
  168.       status = "PeFi"
  169.     end,
  170.   },
  171.     force_exit={
  172.     x=22,
  173.     y=30,
  174.     width=18,
  175.     height=1,
  176.     text="Force Exit",
  177.     action=function()
  178.       cutoff_temp = 10500
  179.       ideal_temp = 2000
  180.       ideal_strength = 55
  181.       cutoff_field = 0.45
  182.       state = "Manual Shutdown"
  183.       reactor.stopReactor()
  184.       gpu.setResolution(gpu.maxResolution())
  185.       event_loop = false
  186.     end,
  187.     condition=function() return running or shutting_down end
  188.   },
  189.     update={
  190.     x=22,
  191.     y=32,
  192.     width=18,
  193.     height=1,
  194.     text="Update",
  195.     action=function()
  196.       os.execute("pastebin get -f FZu65NqP DC9; cls; DC9")
  197.     end,
  198.     condition=function() return safe end
  199.   },
  200.     switch_gates={
  201.     x=2,
  202.     y=32,
  203.     width=18,
  204.     height=1,
  205.     text="Swap flux gates",
  206.     action=function()
  207.       cutoff_temp = 10500
  208.       local old_addr = flux_in.address
  209.       flux_in = component.proxy(flux_out.address)
  210.       flux_out = component.proxy(old_addr)
  211.     end,
  212.     condition=function() return safe end
  213.   },
  214.     exit={
  215.     x=22,
  216.     y=30,
  217.     width=18,
  218.     height=1,
  219.     text="Exit",
  220.     action=function()
  221.       event_loop = false
  222.     end,
  223.     condition=function() return safe end
  224.   },
  225.   temp_up_max={
  226.     x=temp_adjust_x_offset,
  227.     y=temp_adjust_y_offset,
  228.     width=adj_button_width,
  229.     height=1,
  230.     text="Maximum",
  231.     action=function()
  232.       ideal_temp = 8000
  233.     end
  234.   },
  235.   temp_up_thousand={
  236.     x=temp_adjust_x_offset,
  237.     y=temp_adjust_y_offset+2,
  238.     width=adj_button_width,
  239.     height=1,
  240.     text="+1000",
  241.     action=function() modify_temp(1000) end
  242.   },
  243.   temp_up_hundred={
  244.     x=temp_adjust_x_offset,
  245.     y=temp_adjust_y_offset+4,
  246.     width=adj_button_width,
  247.     height=1,
  248.     text="+100",
  249.     action=function() modify_temp(100) end
  250.   },
  251.   temp_up_ten={
  252.     x=temp_adjust_x_offset,
  253.     y=temp_adjust_y_offset+6,
  254.     width=adj_button_width,
  255.     height=1,
  256.     text="+10",
  257.     action=function() modify_temp(10) end
  258.   },
  259.   temp_up_one={
  260.     x=temp_adjust_x_offset,
  261.     y=temp_adjust_y_offset+8,
  262.     width=adj_button_width,
  263.     height=1,
  264.     text="+1",
  265.     action=function() modify_temp(1) end
  266.   },
  267.   temp_down_thousand={
  268.     x=temp_adjust_x_offset,
  269.     y=temp_adjust_y_offset+18,
  270.     width=adj_button_width,
  271.     height=1,
  272.     text="-1000",
  273.     action=function() modify_temp(-1000) end
  274.   },
  275.     temp_down_max={
  276.     x=temp_adjust_x_offset,
  277.     y=temp_adjust_y_offset+20,
  278.     width=adj_button_width,
  279.     height=1,
  280.     text="Minimum",
  281.     action=function() modify_temp(-20000) end
  282.   },
  283.   temp_down_hundred={
  284.     x=temp_adjust_x_offset,
  285.     y=temp_adjust_y_offset+16,
  286.     width=adj_button_width,
  287.     height=1,
  288.     text="-100",
  289.     action=function() modify_temp(-100) end
  290.   },
  291.   temp_down_ten={
  292.     x=temp_adjust_x_offset,
  293.     y=temp_adjust_y_offset+14,
  294.     width=adj_button_width,
  295.     height=1,
  296.     text="-10",
  297.     action=function() modify_temp(-10) end
  298.   },
  299.   temp_down_one={
  300.     x=temp_adjust_x_offset,
  301.     y=temp_adjust_y_offset+12,
  302.     width=adj_button_width,
  303.     height=1,
  304.     text="-1",
  305.     action=function() modify_temp(-1) end
  306.   },
  307.   field_up_ten={
  308.     x=field_adjust_x_offset,
  309.     y=field_adjust_y_offset+3,
  310.     width=adj_button_width,
  311.     height=1,
  312.     text="+10",
  313.     action=function() modify_field(10) end
  314.   },
  315.     field_up_one={
  316.     x=field_adjust_x_offset,
  317.     y=field_adjust_y_offset+5,
  318.     width=adj_button_width,
  319.     height=1,
  320.     text="+1",
  321.     action=function() modify_field(1) end
  322.   },
  323.   field_up_tenth={
  324.     x=field_adjust_x_offset,
  325.     y=field_adjust_y_offset+7,
  326.     width=adj_button_width,
  327.     height=1,
  328.     text="+0.1",
  329.     action=function() modify_field(0.1) end
  330.   },
  331.   field_down_ten={
  332.     x=field_adjust_x_offset,
  333.     y=field_adjust_y_offset+17,
  334.     width=adj_button_width,
  335.     height=1,
  336.     text="-10",
  337.     action=function() modify_field(-10) end
  338.   },
  339.     field_down_one={
  340.     x=field_adjust_x_offset,
  341.     y=field_adjust_y_offset+15,
  342.     width=adj_button_width,
  343.     height=1,
  344.     text="-1",
  345.     action=function() modify_field(-1) end
  346.   },
  347.   field_down_tenth={
  348.     x=field_adjust_x_offset,
  349.     y=field_adjust_y_offset+13,
  350.     width=adj_button_width,
  351.     height=1,
  352.     text="-0.1",
  353.     action=function() modify_field(-0.1) end
  354.   }
  355. }
  356.  
  357.  -- main code
  358.  
  359. flux_in.setFlowOverride(0)
  360. flux_out.setFlowOverride(0)
  361. flux_in.setOverrideEnabled(true)
  362. flux_out.setOverrideEnabled(true)
  363.  
  364. local condition = reactor.getReactorInfo()
  365. if not condition then
  366.   print("Reactor not initialized, please ensure the stabilizers are properly laid out.")
  367.   os.exit()
  368. end
  369.  
  370. ideal_strength = 15
  371.  
  372. ideal_temp = 8000
  373. cutoff_temp = 8001
  374.  
  375.  -- tweakable pid gains
  376.  
  377. inflow_P_gain = 1
  378. inflow_I_gain = 0.04
  379. inflow_D_gain = 0.05
  380.  
  381. outflow_P_gain = 500
  382. outflow_I_gain = 0.10
  383. outflow_II_gain = 0.0000003
  384. outflow_D_gain = 30000
  385.  
  386.  -- initialize main loop
  387.  
  388. inflow_I_sum = 0
  389. inflow_D_last = 0
  390.  
  391. outflow_I_sum = 0
  392. outflow_II_sum = 0
  393. outflow_D_last = 0
  394.  
  395. state = "Standby"
  396. shutting_down = false
  397.  
  398. if condition.temperature > 25 then
  399.   state = "Cooling"
  400. end
  401. if condition.temperature > 2000 then
  402.   state = "Active"
  403. end
  404.  
  405.  -- Possible states:
  406.   --Standby
  407.   --Charging
  408.   --Active
  409.   --Manual Shutdown
  410.   --Emergency Shutdown
  411.   --Cooling
  412.  
  413. event_loop = true
  414. while event_loop do
  415.  
  416.   if not component.isAvailable("draconic_reactor") then
  417.     exit_msg("Reactor disconnected, exiting")
  418.   end
  419.  
  420.   if not component.isAvailable("flux_gate") then
  421.     exit_msg("Flux gates disconnected, exiting")
  422.   end
  423.  
  424.     local info = reactor.getReactorInfo()
  425.  
  426.  -- Highest Heat Value
  427.  
  428. if info.temperature > highest_temp then
  429.   highest_temp = info.temperature
  430. end
  431.  
  432.  -- Highest Sat Value
  433.  
  434. if ((info.energySaturation / info.maxEnergySaturation) * 100) > highest_sat then
  435.   highest_sat = ((info.energySaturation / info.maxEnergySaturation) * 100)
  436. end
  437.  
  438.  -- Lowest Field Value ((1 - info.fuelConversion / info.maxFuelConversion) * 100)
  439.  
  440. if ((info.fieldStrength / info.maxFieldStrength) * 100) < lowest_field then
  441.   lowest_field = ((info.fieldStrength / info.maxFieldStrength) * 100)
  442. end
  443.  
  444.  -- Lowest Field Value
  445.  
  446. if ((1 - info.fuelConversion / info.maxFuelConversion) * 100) < lowest_fuel then
  447.   lowest_fuel = ((1 - info.fuelConversion / info.maxFuelConversion) * 100)
  448. end
  449.  
  450.   local inflow = 0
  451.   local outflow = 0
  452.  
  453.   shutting_down = state == "Manual Shutdown" or state == "Emergency Shutdown"
  454.   running = state == "Charging" or state == "Active"
  455.   safe = state == "Standby" or state == "Cooling"
  456.  
  457.   if state == "Charging" then
  458.     inflow = 5000000
  459.  
  460.     if info.temperature > 2000 then
  461.       reactor.activateReactor()
  462.       state = "Active"
  463.     end
  464.   elseif state == "Cooling" then
  465.     if info.temperature < 25 then
  466.       state = "Standby"
  467.     end
  468.     inflow = 10
  469.     outflow = 20
  470.   elseif state == "Standby" then
  471.     inflow = 10
  472.     outflow = 20
  473.   else
  474.     -- adjust inflow rate based on field strength
  475.    
  476.     field_error = (info.maxFieldStrength * (ideal_strength / 100)) - info.fieldStrength
  477.     proportional_field_error = field_error * inflow_P_gain
  478.     inflow_I_sum = inflow_I_sum + field_error
  479.     integral_field_error = inflow_I_sum * inflow_I_gain
  480.     derivative_field_error = (field_error - inflow_D_last) * inflow_D_gain
  481.     inflow_D_last = field_error
  482.     inflow_correction = proportional_field_error + integral_field_error + derivative_field_error
  483.     if inflow_correction < 0 then
  484.       inflow_I_sum = inflow_I_sum - field_error
  485.     end
  486.     inflow = inflow_correction
  487.  
  488.     if not shutting_down then
  489.  
  490.       -- adjust outflow rate based on core temperature
  491.  
  492.       temp_error = ideal_temp - info.temperature
  493.       proportional_temp_error = temp_error * outflow_P_gain
  494.       outflow_I_sum = outflow_I_sum + temp_error
  495.       integral_temp_error = outflow_I_sum * outflow_I_gain
  496.       if math.abs(temp_error) < 100 then
  497.         outflow_II_sum = outflow_II_sum + integral_temp_error
  498.       else
  499.         outflow_II_sum = 0
  500.       end
  501.       second_integral_temp_error = outflow_II_sum * outflow_II_gain
  502.       derivative_temp_error = (temp_error - outflow_D_last) * outflow_D_gain
  503.       outflow_D_last = temp_error
  504.       outflow_correction = proportional_temp_error + integral_temp_error + second_integral_temp_error + derivative_temp_error
  505.       if outflow_correction < 0 then
  506.         outflow_I_sum = outflow_I_sum - temp_error
  507.       end
  508.       outflow = outflow_correction
  509.  
  510.       -- cut off reactor in case of emergency
  511.  
  512.       if info.temperature > cutoff_temp then
  513.         print("Reactor Too Hot, shutting down")
  514.         state = "Emergency Shutdown"
  515.         status = "HiTe"
  516.         reactor.stopReactor()
  517.       end
  518.       if ((info.fieldStrength / info.maxFieldStrength) * 100) < cutoff_field then
  519.         print("Reactor Field Has Failed, Failsafe Activated, Shutting Down")
  520.         state = "Emergency Shutdown"
  521.         status = "LoFi"
  522.         reactor.stopReactor()
  523.       end
  524.       if ((1 - info.fuelConversion / info.maxFuelConversion) * 100) < 1.25 then
  525.         print("Reactor Fuel Low, Shutting Down")
  526.       state = "Emergency Shutdown"
  527.       status = "LoFu"
  528.       reactor.stopReactor()
  529.       end
  530.     else
  531.       if info.temperature < 2000 then
  532.         state = "Cooling"
  533.       end
  534.     end
  535.   end
  536.  
  537.   if state ~= "Active" and not shutting_down then
  538.     inflow_I_sum = 0
  539.     inflow_D_last = 0
  540.     outflow_I_sum = 0
  541.     outflow_II_sum = 0
  542.     outflow_D_last = 0
  543.   end
  544.  
  545.   if inflow < 0 then
  546.     inflow = 0
  547.   end
  548.   if outflow < 0 then
  549.     outflow = 0
  550.   end
  551.  
  552.   inflow = math.floor(inflow)
  553.   outflow = math.floor(outflow)
  554.  
  555.   flux_in.setFlowOverride(inflow)
  556.   flux_out.setFlowOverride(outflow)
  557.  
  558.   -- Draw screen
  559.  
  560.   if term.isAvailable() then
  561.  
  562.     -- Draw Values
  563.  
  564. function modify_eff(offset)
  565.   local eff = ((outflow / inflow) * 100)
  566.   if eff > 100000 then
  567.     eff = 1
  568.   end
  569. end
  570.  
  571.     local secondsToExpire = (info.maxFuelConversion - info.fuelConversion) / math.max(info.fuelConversionRate*0.00002, 0.00001)
  572.  
  573.     local left_margin = 2
  574.     local spacing = 1
  575.     local values = {
  576. string.format("      Estimated time to refuel: %2dd, %2dh, %2dm, %2ds", secondsToExpire/86400, secondsToExpire/3600 % 24, secondsToExpire/60 % 60, secondsToExpire % 60),
  577.       " ",
  578.               "                  Reactor Statistics",
  579.               "----------------------------------------------------------",
  580. string.format("Ideal Field:                |           %5.1f%%           |", ideal_strength),
  581. string.format("Current Field:              |  %7.1f%% (%11.1fRF)  |", ((info.fieldStrength / info.maxFieldStrength) * 100), ((info.fieldStrength / info.maxFieldStrength) * 100000000)),
  582.               "----------------------------|----------------------------|",
  583. string.format("Fuel Remaining:             |           %5.1f%%           |", ((1 - info.fuelConversion / info.maxFuelConversion) * 100)),
  584. string.format("Fuel Use Rate:              |%10.1f nb/t (%4.2f Nu/s) |", info.fuelConversionRate, ((info.fuelConversionRate / 50000) / 16)),
  585.               "----------------------------|----------------------------|",
  586. string.format("Temperature                 |   %7.1f°c (%7.1f°f)    |", info.temperature, ((info.temperature * 1.8) + 32)),
  587. string.format("Ideal Temperature:          |   %7.1f°c (%7.1f°f)    |", ideal_temp, ((ideal_temp * 1.8) + 32)),
  588.               "----------------------------|----------------------------|",
  589. string.format("Energy Input:               |   %12.1f RF/t        |", inflow),
  590. string.format("Energy Output:              |   %12.1f RF/t        |", outflow),
  591. string.format("Energy Efficiency:          |   %12.1f%%            |", ((outflow / inflow) * 100)),
  592. string.format("Energy Profit:              |  %13.1f RF/t        |", (outflow - inflow)),
  593.               "----------------------------------------------------------",
  594.               "                                                         ",
  595.               "                    Debug Information                    ",
  596.               "                                                         ",
  597. string.format("Max Field Drop:             |        %5.2f%%              ", lowest_field),
  598. string.format("Lowest Recorded Fuel:       |        %5.2f%%              ", lowest_fuel),
  599. string.format("Max Temp Spike:             |     %8.2f              ", highest_temp),
  600. string.format("Max Saturation:             |       %6.2f%%              ", highest_sat),
  601.               "Status:                     |  " .. state .. "-" .. status .. "               ",
  602.               "----------------------------------------------------------",
  603.               " ",
  604.               " ",
  605.               " ",
  606.               " ",
  607.               " ",
  608.               " ",
  609.               " ",
  610.               " ",
  611.               " ",
  612.               " ",
  613.               " ",
  614.               " ",
  615.               " ",
  616.               " ",
  617.               " ",
  618. "                                                PID Values",
  619.               " ",
  620. "                     P             IS            I             D             DL            C",
  621. string.format("        Input:  %12.1f, %12.1f, %12.1f, %12.1f, %12.1f, %12.1f", proportional_field_error, inflow_I_sum, integral_field_error, derivative_field_error, inflow_D_last, inflow_correction),
  622. string.format("        Output: %12.1f, %12.1f, %12.1f, %12.1f, %12.1f, %12.1f", proportional_temp_error, outflow_I_sum, integral_temp_error, derivative_temp_error, outflow_D_last, outflow_correction),    
  623. }
  624.  
  625.  
  626.     term.clear()
  627.    
  628.     for i, v in ipairs(values) do
  629.       term.setCursor(left_margin, i * spacing)
  630.       term.write(v)
  631.     end
  632.  
  633.     -- Draw button values
  634.  
  635.     term.setCursor(temp_adjust_x_offset, temp_adjust_y_offset+10)
  636.     term.write("Reactor Temperature")
  637.     term.setCursor(field_adjust_x_offset+1, field_adjust_y_offset+10)
  638.     term.write("Field Strength")
  639.  
  640.     -- Draw Buttons
  641.  
  642.     gpu.setForeground(0x000000)
  643.  
  644.     for bname, button in pairs(buttons) do
  645.       if button.depressed then
  646.  
  647.         button.depressed = button.depressed - 1
  648.         if button.depressed == 0 then
  649.           button.depressed = nil
  650.         end
  651.       end
  652.       if button.condition == nil or button.condition() then
  653.         local center_color = 0xAAAAAA
  654.         local highlight_color = 0xCCCCCC
  655.         local lowlight_color = 0x808080
  656.         if button.depressed then
  657.           center_color = 0x999999
  658.           highlight_color = 0x707070
  659.           lowlight_color = 0xBBBBBB
  660.         end
  661.         gpu.setBackground(center_color)
  662.         gpu.fill(button.x, button.y, button.width, button.height, " ")
  663.         if button.width > 1 and button.height > 1 then
  664.           gpu.setBackground(lowlight_color)
  665.           gpu.fill(button.x+1, button.y+button.height-1, button.width-1, 1, " ")
  666.           gpu.fill(button.x+button.width-1, button.y, 1, button.height, " ")
  667.           gpu.setBackground(highlight_color)
  668.           gpu.fill(button.x, button.y, 1, button.height, " ")
  669.           gpu.fill(button.x, button.y, button.width, 1, " ")
  670.         end
  671.         gpu.setBackground(center_color)
  672.         term.setCursor(button.x + math.floor(button.width / 2 - #button.text / 2), button.y + math.floor(button.height / 2))
  673.         term.write(button.text)
  674.       end
  675.     end
  676.  
  677.     gpu.setBackground(0x000000)
  678.     gpu.setForeground(0xFFFFFF)
  679.   end  
  680.  
  681.   -- Wait for next tick, or manual shutdown
  682.  
  683.   local event, id, op1, op2 = event.pull(0.05)
  684.   if event == "interrupted" then
  685.     if safe then
  686.       break
  687.     end
  688.   elseif event == "touch" then
  689.    
  690.     -- Handle Button Presses
  691.  
  692.     local x = op1
  693.     local y = op2
  694.  
  695.     for bname, button in pairs(buttons) do
  696.       if (button.condition == nil or button.condition()) and x >= button.x and x <= button.x + button.width and y >= button.y and y <= button.y + button.height then
  697.         button.action()
  698.         button.depressed = 3
  699.       end
  700.     end
  701.   end
  702. end
  703.  
  704. term.clear()
Add Comment
Please, Sign In to add comment