IceG4merBR 0 Posted May 6, 2018 Share Posted May 6, 2018 I did this program, it's very simple, but i want to terminate it and i don't know how to do it... I tried Ctrl + C, Ctrl + Alt + C. I need some help. local component = require("component") local term = require("term") local event = require("event") local keyboard = require("keyboard") local cube = component.basic_energy_cube local computer = component.computer local gpu = component.gpu local w, h =gpu.getResolution() local colors = {} colors.gray = 0x555555 colors.red = 0xFF0000 colors.lime = 0x00FF00 function label(x, y, message, color, ...) local color = color or gpu.getForeground() local oldColor = gpu.getForeground() gpu.setForeground(color) term.setCursor(x, y) print(string.format(message, ...)) gpu.setForeground(oldColor) end function toMRf(val) return val / 1000000 end function toJ(val) return val / 4 / 100000 end os.sleep(2) term.clear() computer.beep(1000,1.5) while true do energy = toMRf(cube.getEnergyStored()) energyMax = toMRf(cube.getMaxEnergyStored()) energyJ = toJ(cube.getEnergyStored()) energyMaxJ = toJ(cube.getMaxEnergyStored()) label(1, 1, "%.2f MRf / %.2f MJ (Energia Acumulada)", colors.red, energy, energyJ ) label(1, 3, "%.2f MRf / %.2f MJ (Capacidade da bateria)", colors.lime, energyMax, energyMaxJ) end Quote Link to post Share on other sites
1 Solution Molinko 43 Posted May 6, 2018 Solution Share Posted May 6, 2018 Your program has an infinite loop. You'll need to yield either with sleep or by pulling an event. Here is a simple solution. repeat energy = toMRf(cube.getEnergyStored()) energyMax = toMRf(cube.getMaxEnergyStored()) energyJ = toJ(cube.getEnergyStored()) energyMaxJ = toJ(cube.getMaxEnergyStored()) label(1, 1, "%.2f MRf / %.2f MJ (Energia Acumulada)", colors.red, energy, energyJ ) label(1, 3, "%.2f MRf / %.2f MJ (Capacidade da bateria)", colors.lime, energyMax, energyMaxJ) until event.pull(1) == "interrupted" -- # change 1 to something smaller to refresh faster IceG4merBR 1 Quote Link to post Share on other sites
0 IceG4merBR 0 Posted May 6, 2018 Author Share Posted May 6, 2018 It's working fine, thanks! Quote Link to post Share on other sites
I did this program, it's very simple, but i want to terminate it and i don't know how to do it... I tried Ctrl + C, Ctrl + Alt + C.
I need some help.
Link to post
Share on other sites