First of all if when you iterate through a table and you try to print a nested table you get a string that looks something like this "table:323fwerf44" or other such gobbledigook, then you can iterate through that too. For example
Code:
for i,v in pairs(parentTable) do
if type(v) == "table" then
for k,w in pairs(v) do -- v is a nestedTable
print(w)
end
else
print(v)
end
end
Like I said a lot of the methods in open peripherals return complicated table structures which are great in that you get loads of useful information but can take a while to actually get all the information you want.
Another good trick that I used to look into complicated table structures without having to mess around with for loops that I wish i remembered earlier is serialization. Computercraft offers a couple of easy serialization functions in the textutils api that allow you to turn a table into a string. You can read this string to find out more about the structure - it reads like a linear version of any table that you write manually.
Now that is out the way I will tell you how I did the Redstone energy cell stuff. This works with the latest stable version of Resonant Rise which is pretty up to date in both mods.
A few details about my set up - the computer is connected to the cell via wired modem and computercraft cable. When I clicked on the modem which was on the cell it gave me a name for the cell which I used to wrap it as a variable. If your cell is adjacent to your computer then replace that big string with the side. What follows is a truncated version of my code which shows the bits that are relevant to redstone energy cells
Code:
local cellName = "cofh_thermalexpansion_energycell_0" -- [[This is right at the top of my program before I do anything else. It sets the name of the cell that was given when I connected it via modem. This is what you replace with side if appropriate]]
local modem = peripheral.wrap("back")
local cell = peripheral.wrap(cellName) -- This wraps the cell using cellName
--This here is the important function
function getRFBuffer() -- A function I wrote to get some data from the cell
print("Scanning Redstone Energy Cell")
local data = {
["capacity"] = {"Cell Capacity", cell.getMaxEnergyStored(cellName)}, -- This method gets the max energy that can be stored, the parameter is the name the cell if you are on wired modems (or probably - cont. on next line
["stored"] = {"Current Buffer", cell.getEnergyStored(cellName)}, --cont.- probably the side of the computer the cell is on if it is directly adjacent)
} -- This is a nested table btw
tablePrint(data) -- Ignore this line it is a debugging tool that I forgot to take out.
print("Finished Scanning Redstone Energy Cell")
return data
end
function setRFBuffer() -- This function draws a barchart to show how full the cell is. I am using the barChart to monitor this cell because it is a buffer for my ME system
--Reading through this function and the mainProg() function is not really necessary. I just put them in so you can seem the stuff working in situ
local powerBuffer = getRFBuffer() -- As you can see here, I get the data from getRFBuffer and store it in a new table here which I use to get information to display on a monitor
local sX = 4 -- You can ignore most of these values because they are just there to make sure that the barchart draws where I want it to.
local sY = 3
monitor.setCursorPos(sX,sY)
local bufferHeader = "Energy Reserves"
monitor.write(bufferHeader)
local len = string.len(bufferHeader)
local width = len-4
local height = 17
local bars = round((powerBuffer["stored"][2]/powerBuffer["capacity"][2])*height,0) -- This is the variable I pass to barChart to tell it how full it needs to be shown as. If you look the calculation is just like a percentage
barChart({sX+2, sY+1}, {width, height}, bars) -- This is the barChart function I wrote
local cX,cY = monitor.getCursorPos()
print(cX..":"..cY)
monitor.setCursorPos(sX,cY+2)
monitor.setBackgroundColor(colors.black)
local r = round(powerBuffer["stored"][2]/powerBuffer["capacity"][2]*100, 2)
monitor.write("RF Levels: "..r.."%")
print("Energy Storage Monitor Set")
end
function mainProg()
monitor.clear()
monCentre("Bonnibel's ME System", 1)
setRFBuffer()
setStorageInfo()
local x,y = monitor.getCursorPos()
local menu = setMenu({x,y})
mainEventHandler(menu)
end
This only a tiny bit of the code but hopefully it tells you what you need to know. I put in some extra information too just in case it helps.