Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
IceG4merBR

How can i terminate this program?

Question

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

 

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 1
  • Solution

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

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.