Jump to content




Program outputting changing non descript error messages.

help lua

2 replies to this topic

#1 knight0834

  • New Members
  • 2 posts

Posted 20 February 2017 - 04:43 AM

Hello,

So I'm attempting to make my own program to help me monitor and control my Big Reactors reactor with a custom gui made from a buttons api and progressbars api. I've made the GUI for my advanced monitors. I finally sat down to finish the code and after much learning and work i've come up with this.

os.loadAPI("button")
os.loadAPI("progressbar")
progressbar.SetPeripheral("top")
reactor = peripheral.wrap("BigReactors-Reactor_0")
m = peripheral.wrap("top")
m.clear()
fuelTemp = 1
casingTemp = 1
fuel = 1
waste = 1
energy = 1
energyLT = 1
rodLevels = 0
active = false

function fillTables()
  button.setTable("Power Switch", power, 10,28,3,5)
  button.setTable("Up One", upOne, 4,18,7,9)
  button.setTable("Up Five", upFive, 4,18,11,13)
  button.setTable("Up Hundred", upHundred, 4,18,15,17)
  button.setTable("Down One", downOne, 20,34,7,9)
  button.setTable("Down Five", downFive, 20,34,11,13)
  button.setTable("Down Hundred", downHundred, 20,34,15,17)
  progressbar.SetTable("Fuel Temp", 2500, 1, 41,66,7)
  progressbar.SetTable("Casing Temp", 2500, 1, 41,66,9)
  progressbar.SetTable("Fuel", 700000, 1, 41,66,11)
  progressbar.SetTable("Waste", 700000, 1, 41,66,13)
  progressbar.SetTable("Energy Stored", 10000000, 1, 41,66,15)
  progressbar.SetTable("Energy Last Tick", 42000, 1, 41,66,17)
  button.screen()
  progressbar.DrawToPeripheral()
end

function createLabels()
  button.heading("Reactor Control Panel")
  button.label(50,4, "Readings:")
  button.label(39,7, "0")
  button.label(50,6,"Fuel Temp")
  button.label(68,7, "2.5k")
  button.label(39,9, "0")
  button.label(49,8,"Casing Temp")
  button.label(68,9, "2.5k")
  button.label(39,11, "0")
  button.label(52,10,"Fuel")
  button.label(68,11, "700k")
  button.label(39,13,"0")
  button.label(52,12,"Waste")
  button.label(68,13, "700k")
  button.label(39,15, "0")
  button.label(48,14,"Energy Stored")
  button.label(68,15, "10m")
  button.label(39,17, "0")
  button.label(47,16,"Energy Last Tick")
  button.label(68,17, "42k")
end

function power()
  active = reactor.getActive()
  if active == false then
    reactor.setActive(true)
    active = true
    button.toggleButton("Power Switch")
  else
  end
end

function upOne()
  button.flash("Up One")
  active = reactor.getActive()
  if active == true then
    if rodLevels <= 100 then
    else
    rodLevels = rodLevels + 1
    reactor.setAllControlRodLevels(rodLevels)
    end
  else
  end
end

function upFive()
  button.flash("Up Five")
  active = reactor.getActive()
  if active == true then
    if rodLevels <= 100 then
    else
    rodLevels = rodLevels + 5
    reactor.setAllControlRodLevels(rodLevels)
    end
  else
  end
end

function upHundred()
  button.flash("Up Hundred")
  active = reactor.getActive()
  if active == true then
    if rodLevels <= 100 then
    else
    rodLevels = rodLevels + 100
    reactor.setAllControlRodLevels(rodLevels)
    end
  else
  end
end 

function downOne()
  button.flash("Down One")
  active = reactor.getActive()
  if active == true then
    if rodLevels <= 0 then
    else
    rodLevels = rodLevels - 1
    reactor.setAllControlRodLevels(rodLevels)
    end
  else
  end
end

function downFive()
  button.flash("Down Five")
  active = reactor.getActive()
  if active == true then
    if rodLevels <= 0 then
    else
    rodLevels = rodLevels - 5
    reactor.setAllControlRodLevels(rodLevels)
    end
  else
  end
end

function downHundred()
  button.flash("Down Hundred")
  active = reactor.getActive()
  if active == true then
    if rodLevels <= 0 then
    else
    rodLevels = rodLevels - 100
    reactor.setAllControlRodLevels(rodLevels)
    end
  else
  end
end

function updateReadings()
  progressbar.SetCurValue("Fuel Temp", fueltemp)
  progressbar.SetCurValue("Casing Temp", casingtemp)
  progressbar.SetCurValue("Fuel", fuel)
  progressbar.SetCurValue("Waste", waste)
  progressbar.SetCurValue("Energy Stored", energy)
  progressbar.SetCurValue("Energy Last Tick", energyLT)
  progressbar.DrawToPeripheral()
end

function getUpdatedReadings()
  fuelTemp = reactor.getFuelTemperature
  casingTemp = reactor.getCasingTemperature
  fuel = reactor.getFuelAmount
  waste = reactor.getWasteAmount
  energy = reactor.getEnergyStored
  energyLT = reactor.getEnergyProducedLastTick
  updateReadings()

  sleep(2)
end

function getClick()
  event, side, x, y = os.pullEvent("monitor_touch")
  button.checkxy(x,y)
end 

	
fillTables()
createLabels()
reactor.setAllControlRodLevels(0)
reactor.setActive(false)
getUpdatedReadings()

refresh = true
while refresh do
  parallel.waitForAny(getUpdatedReadings,getClick)
end

I went to run it after double checking myself for typos etc. The result of my running it was a random two digit error code in red with no description. Hoping it was a random error I ran it again immediately after rechecking for typos and obvious issues. This time it returned a different two digit error code in red. Starting to get frustrated after yet again checking the code i started to spam it and noticed i got a two or three more different two digit error codes all of which have no description.

Help?!?

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 20 February 2017 - 09:58 AM

Sometimes rebooting the computer in concern sorts this out, but sometimes its the fault of a peripheral mod's function (eg BigReactors) hiding the true error.

If the worst comes to worst, adding extra print statements throughout your script should allow you to narrow it down to the line which actually crashes the script.

#3 knight0834

  • New Members
  • 2 posts

Posted 20 February 2017 - 06:23 PM

Yea I found the issue i had some typos in my big reactors functions located in the getUpdatedReadings Function.

So my program is now working without error so far. I was wondering two things though as im still working on it. I like my gui so far the only thing i dont like is that the progressbar api i got doesnt show the number of the variables (ie rf/t) on the status bars. it just shows [ ] at the ends. i don't know enough about how progress bars work hence why i got the api. I was hoping someone could take my api and edit it for me (explaining so i can learn of course) so that the progress bars show the variables for in the middle of them.

here is the code.

local monitor
local hasMonitor = false
local ProgressBar = {}
local FillColor = colors.orange
local EmptyColor = colors.blue
local TextColor = colors.white

function SetPeripheral(side)
  if (peripheral.isPresent(side)) then
    monitor = peripheral.wrap(side)
    hasMonitor = true
  end
end

function SetTable(name, maxVal, curVal, xmin, xmax, y)
  ProgressBar[name] = {}
  ProgressBar[name]["Max"] = maxVal
  ProgressBar[name]["Current"] = curVal
  ProgressBar[name]["XMin"] = xmin
  ProgressBar[name]["XMax"] = xmax
  ProgressBar[name]["YVal"] = y
end

function ClearTable()
  if (hasMonitor) then
    ProgressBar = {}
  end
end

function SetFillColor(color)
  if (colors.combine(color,color)) then 
    FillColor = color
  end
end

function SetEmptyColor(color)
  if (colors.combine(color,color)) then
    EmptyColor = color
  end
end

function SetTextColor(color)
  if (colors.combine(color,color)) then
    TextColor = color
  end
end

function SetMaxValue(name, intVal)
  if (ProgressBar[name]) then
    ProgressBar[name]["Max"] = intVal
  end
end

function SetCurValue(name, intVal)
  if (ProgressBar[name]) then
    ProgressBar[name]["Current"] = intVal
  end
end

function DrawToPeripheral()
  if (hasMonitor) then
    for name, data in pairs(ProgressBar) do
	  DrawBar(name, data)
    end
  end
end

function DrawBar(name, arr)
  local y = arr["YVal"]
  local fill = math.floor((arr["XMax"] - arr["XMin"]) * (arr["Current"] / arr["Max"]))

  monitor.setBackgroundColor(FillColor)
  monitor.setTextColor(TextColor)

  for x = arr["XMin"], arr["XMax"] do
    local num = math.floor(x - arr["XMin"])
    monitor.setCursorPos(x,y)

    if (num > fill) then
	  monitor.setBackgroundColor(EmptyColor)
    end

    if (num == 0) then
	  monitor.write("[")
    end
    if (x == arr["XMax"]) then
	  monitor.write("]")
    else
	  monitor.write(" ")
    end
  end

  monitor.setBackgroundColor(colors.black)
end

Thanks in advance! :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users