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

[Question] CCSensor information readout...

Started by glenmack, 25 October 2012 - 08:13 PM
glenmack #1
Posted 25 October 2012 - 10:13 PM
Hi,

Just started teaching myself Lua today in order to get a Nuclear reactor up and running… only, I can't get past the probe/target level to read things in CCSensor…

I've just been working through it logically for hours… so far I have gotten a retardedly short way…

–Angel Over-Reactor Program v.1.0–

print ("–Angel Over-Reactor Program v1.0–")
sleep(1)
print("Loading…")
sleep(1)

os.unloadAPI("sensors")
os.loadAPI("/rom/apis/sensors")
–line 10–
ctr = sensors.getController()
sen = sensors.getSensors(ctr)
tar = sensors.getSensorInfo(ctr,sen)

for k, v in pairs(tar) do print(k, V) end

print(tar)

for i=1,# tar do
print(i,". ", tar)
end


I've tried virtually every API command on the tar line to get it to print for me the next level of probe, or target, or whatever comes next in CCSensors hierarchy of madness.

What I want is access to the table of readings from the reactor and be able to print them or assign them variables or strings, or whatever, so I can get to the math and redpower bit of this. So I know I need the Probe name, and the target, and the reading (type?) which are located in table or dictionaries. If someone could show me a way to a ) have each level of these printed out, (I know I don't particularly need this, but it's been helpful at the controller and sensor level to help me understand) and b ) start connecting them up in Lua in such a way that means it will work no matter the actual name of the probe, like I have with the sensor and controller. I assume the readings already have an API string/variable (I don't know what to be calling them) so I'll need to be able to print them for me understand too I can take it from there.

Thanks in advance.
ChunLing #2
Posted 26 October 2012 - 02:35 AM
When you use "print(tar)", the output is just "table: hxhxhx" where hxhxhx is some random hexidecimal number, right?

If you want to print out a table, there are a couple of options. The most complete is using textutils.serialize() to turn the table into an lua string. Or you can use unpack(), though this will lose some information. Try "print(textutils.serialize(tar))" and see what you get.