0

コマンドラインバージョンのluaですべての機能を実行できるという問題がありますが、プログラムを実行してもエラーは発生せず、終了するだけです。これを診断する方法がわかりませんが、さまざまなことに対してエラーを数回スローしようとしましたが、エラーが発生してエラーが出力されます。

power = peripheral.wrap("bottom")
mon = peripheral.wrap("top")

x,y = mon.getSize()

clearTerm = function()
  term.clear()
  term.setCursorPos(1,1)
end

clearBoth = function()
  clearMon()
  clearTerm()
end

intLen = function(bar)
  tab = tostring(bar)
  tab = string.len(tab)
  return tab
end

checkPower = function()
  total = power.getMaxEnergyStored()
  local til = intLen(total)
  local yy = math.floor(y/2)
  local tol = math.floor(x-til)
  mon.setCursorPos(yy+0,tol/2)
  for z=1,til do mon.write("-") end
  mon.setCursorPos(yy-1,tol/2)
  mon.write(total)
  while true do
    current = power.getEnergyStored()
    local cil = intLen(current)
    local col = math.floor(x-cil)
    mon.setCursorPos(yy+1,col/2)
    mon.write(current)
    sleep(1)
  end
end

プログラム全体のペーストビンへのリンクもここに残しておきます。

4

1 に答える 1

0

まず、コードにいくつかの出力を追加できます。のようなものを追加するだけです

print "1" -- debug output
...
print "2" -- debug output
...
-- don't forget to remove these after you're done debugging!

プログラムを実行したときに表示されるコードの数を確認してください。このようにして、プログラムがクラッシュした正確な時期を絞り込むことができます。

また、関数 clearMon() が定義されている場所を見つけることができません。それが問題の原因である可能性がありますか、それとも他の場所で定義されていますか?

于 2016-03-14T12:51:56.627 に答える