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

How to Create Real-Time Reactor Values

Started by DashinAssasin, 18 September 2012 - 02:20 AM
DashinAssasin #1
Posted 18 September 2012 - 04:20 AM
so im new to computercraft but with the use of many tutorials and videos i was able to set up a program that can monitor heat, output, size, etc. for a nuclear reactor on a Tekkit server. i also managed to get it to show up on a monitor. But my problem is it doesnt update in real-time so i have to reboot the computer to update the values. Im sure there is some way to get it to update, i tried to loop it with "while true do" and all that did was almost blow up the computer =P. Any help is appreciated
NIN3 #2
Posted 18 September 2012 - 04:28 AM
We would love to see your code, it helps alot.

May I segest puting
sleep(o.5)
Into your while true do loop?
Zoinky #3
Posted 18 September 2012 - 06:54 AM
Could we see the code?
DashinAssasin #4
Posted 19 September 2012 - 12:31 AM
Certain events occured that required me to retype my code and i didnt write it down, i cant remember how to display the info on the monitor anymore so i need help with that too now =P Also i forgot to mention that im using ccSensors mod as part of Tekkit

The Code i have is:

os.unloadAPI("sensors")
os.loadAPI("/rom/apis/sensors")
function printDict(data)
 for i,v in pairs(data) do
  print(tostring(i).." - "..tostring(v))
 end
end
ctrl = sensors.getController()
--print(ctrl)
data = sensors.getSensors(ctrl)
--printDict(data)
Sensor = data[1]
data = sensors.getSensorInfo(ctrl,Sensor)
--printDict(data)
data = sensors.getProbes(ctrl,Sensor)
--printDict(data)
Probe = data[2]
data = sensors.getAvailableTargetsforProbe(ctrl,Sensor,Probe)
--printDict(data)
Target = data[1]
data = sensors.getSensorReadingAsDict(ctrl,Sensor,Target,Probe)
printDict(data)
Cranium #5
Posted 19 September 2012 - 12:45 AM
You would still be fine with a while true do loop. Simply do this:

os.unloadAPI("sensors")
os.loadAPI("/rom/apis/sensors")
function printDict(data)
for i,v in pairs(data) do
  print(tostring(i).." - "..tostring(v))
end
end
while true do
ctrl = sensors.getController()
--print(ctrl)
data = sensors.getSensors(ctrl)
--printDict(data)
Sensor = data[1]
data = sensors.getSensorInfo(ctrl,Sensor)
--printDict(data)
data = sensors.getProbes(ctrl,Sensor)
--printDict(data)
Probe = data[2]
data = sensors.getAvailableTargetsforProbe(ctrl,Sensor,Probe)
--printDict(data)
Target = data[1]
data = sensors.getSensorReadingAsDict(ctrl,Sensor,Target,Probe)
printDict(data)
sleep(.1)
end
That will update ever .1 seconds. No explosions.
DashinAssasin #6
Posted 19 September 2012 - 11:16 PM
alright cool thanks, the program works perfectly now.