neuroticfox

DC9.1

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