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

Pulling value out of table

Started by XLT_Frank, 09 May 2014 - 06:14 PM
XLT_Frank #1
Posted 09 May 2014 - 08:14 PM
So I found this pastbin code from a thread on this forum: http://pastebin.com/qzwqx84r

It no longer works because it uses an old version of getTanks instead of getTankInfo. I am trying to revise it.

I created the following program to understand how the table works:

local valve = peripheral.wrap("bottom")
local tank = valve.getTankInfo("bottom")
for key, value in pairs(tank) do
  print(key .. " = " .. tostring(value))
  for a,b in pairs(value) do
	print(a.." "..B)/>/>
  end
end

It produces:

1 = table: 2aa0101
rawName Water
amount 5600000
capacity 5600000
name water
id 1

That pastebin code has the following:

local function tankStats(tank)
		if(tank) then
				local amt = tank["amount"]
				local size = tank["capacity"]
				local filled = (amt and 1 / (size / amt)) or 0
				return amt, size, filled
		else
				return nil;
		end
end
and

local kind = tank["name"]

How do I get the information into that format appropriately? Obviously I will need to change:

			local tank = valve.getTanks("back")[1]
to

			local tank = valve.getTankInfo("back")[1]

I don't think the
Lyqyd #2
Posted 09 May 2014 - 09:37 PM
Moved to Ask a Pro.
blipman17 #3
Posted 10 May 2014 - 06:56 AM
This might help.
http://www.computercraft.info/forums2/index.php?/topic/16804-open-blocks-open-peripherals-gettankinfo-being-seen-as-a-string-and-not-a-table/
XLT_Frank #4
Posted 10 May 2014 - 06:35 PM
This is OBE. I didn't see someone's contribution to the following thread: http://www.computercraft.info/forums2/index.php?/topic/15689-dead-simple-railcraft-tank-monitoring/page__st__60 that fixed a lot of the problem.s