Advertisement
neuroticfox

DC 9.0

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