This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Orcculus's profile picture

My Reactor script will not update.

Started by Orcculus, 12 January 2015 - 09:03 PM
Orcculus #1
Posted 12 January 2015 - 10:03 PM
Hi, so i'm just writing a small script to display big reactor information in the form of bars like
the controller does. It works as intended on first run but does not update the information at
all afterwards. not sure what i have done wrong.


reactor=peripheral.wrap('BigReactors-Reactor_0')
monitor=peripheral.wrap('monitor_1')
--Grab
Fuel=math.floor(((reactor.getFuelAmount()/reactor.getFuelAmountMax())*100)+0.5)
Waste=math.floor(((reactor.getWasteAmount()/reactor.getFuelAmountMax())*100)+0.5)
storedenergy=math.floor(((reactor.getEnergyStored()/10000000)*100)+0.5)
monitor.setTextScale(1)
monitor.setBackgroundColor(colors.black)
--Create Each bar here, to save us time--
function CreateBar(full, hP, vP)
monitor.setCursorPos(hP,vP)
monitor.setBackgroundColor(colors.black)
monitor.setTextColor(colors.white)
if full then
  monitor.setBackgroundColor(colors.yellow)
  monitor.setTextColor(colors.black)
  monitor.write('_____')
  monitor.setBackgroundColor(colors.black)
  monitor.write('_')
else
  monitor.write('')
end
end
--Lets get crackin' ey--
while true do
monitor.clear()
monitor.setCursorPos(1,1)
monitor.setTextColor(colors.black)
--10 bars, 10 increments--
for i=1, tonumber(10) do
if Fuel >= i*10 then
  CreateBar(true, 2, 11-i)
else
  CreateBar(false, 2, 11-i)
end

if storedenergy >= i*10 then
  CreateBar(true, 8, 11-i)
else
  CreateBar(false, 8, 11-i)
end

monitor.setTextColor(colors.black)
end
monitor.setCursorPos(3,11)
monitor.setTextColor(colors.yellow)
monitor.write(Fuel..'%')

monitor.setCursorPos(9,11)
monitor.setTextColor(colors.red)
monitor.write(storedenergy..'%')
monitor.setTextColor(colors.black)
sleep(3)
end

Thanks in advance for any help.
Lyqyd #2
Posted 12 January 2015 - 10:09 PM
You only grab the data once, at the top of the script. You have to actually grab the data more than once if you want to display updated data later. Move those into your while loop.
Orcculus #3
Posted 12 January 2015 - 10:13 PM
Ohhhhhhhhhhhh of course. what a numpty.. thanks for that :)/>
First_One #4
Posted 12 January 2015 - 10:16 PM
It looks like you're only changing the value of your vars (fuel/waste) once at program start, after the first run, you keep using the first read, maybe that's why it's not changing the visuals

;)/> That was a quick reply, i was still typing and two came up… i feel silly right now lol
Edited on 12 January 2015 - 09:18 PM