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

RailCraft Boilers getTankInfo() help

Started by Metalhawk2012, 26 May 2015 - 06:51 PM
Metalhawk2012 #1
Posted 26 May 2015 - 08:51 PM
Im writing a simple code that involves 4 boilers and 4 Big Reactors turbines and displays the data on a 3x3 monitor
Im slowly getting there bit by bit but im having trouble figuring out this getTankInfo() using openperipherals
the code used is similar to this

boiler = peripheral.wrap("solid_fueled_boiler_firebox_0") //This Works fine i can find the boiler on the the network using this line

then i type

boiler.getTankInfo()

which brings up a table displaying the water and steam's capacity and fill percentage

now im having trouble displaying these values on the monitor(Because its a table you cant just write a table)
i have tried this code here but it just brings up Table:######
for i,v in pairs(boiler.getTankInfo()) do print(v) end

any ideas? im pretty new to CC coding
Cranium #2
Posted 26 May 2015 - 09:28 PM
Each entry in getTankInfo() is numerically indexed, for things with multiple fluids.
EDIT: Would post some code, but my editor here is derping for some reason.
Edited on 26 May 2015 - 07:32 PM
Metalhawk2012 #3
Posted 26 May 2015 - 09:51 PM
hmmm doing this "Sorta" got me somewhere

Title:test

boiler = peripheral.wrap("left")
monitor = peripheral.wrap("right")

info = boiler.getTankInfo()

for i=0,#info do

monitor.setCursorPos(1,i)
monitor.write(info)

end

On the monitor it displayed
{contents={amount=4000.0, name=water, id=1.0,rawName=Water},capacity=4000.0}
{contents={amount=32000.0,name=steam, id=31.0,rawName=Steam},capacity=32000.0}
Metalhawk2012 #4
Posted 26 May 2015 - 10:36 PM
im stuck again i don't know how to get the values out of this table
flaghacker #5
Posted 26 May 2015 - 11:07 PM
Try reading this tutorial:
http://lua-users.org/wiki/TablesTutorial
Metalhawk2012 #6
Posted 27 May 2015 - 12:25 AM
Tried Most of those nothing came out of it
it would sometimes display 1.0 or 2.0
and other times it would display the entire table
Here is the Test code im using at the moment.

boiler = peripheral.wrap("left")
monitor = peripheral.wrap("right")

monitor.setTextScale(0.5)
info = boiler.getTankInfo()
monitor.clear()
monitor.setCursorPos(1,1)

for i=0,#info do

monitor.setCursorPos(1,i)
monitor.write(info)

end

The Answer might be in there but i lack the experience to figure it out
Edited on 26 May 2015 - 10:27 PM
Bomb Bloke #7
Posted 27 May 2015 - 01:01 AM
You would likely learn a lot by reading through this thread.
Metalhawk2012 #8
Posted 27 May 2015 - 02:26 AM
You would likely learn a lot by reading through this thread.
Nope, Tried what he did all i got was "Water" or "Steam" got no capacity or amount
Edited on 27 May 2015 - 12:27 AM
KingofGamesYami #9
Posted 27 May 2015 - 03:47 AM
So you know (I'm assuming) how to get these two tables, but not how to access them:

{contents={amount=4000.0, name=water, id=1.0,rawName=Water},capacity=4000.0}
{contents={amount=32000.0,name=steam, id=31.0,rawName=Steam},capacity=32000.0} 

For now, let's look at the first table (I'll refer to it as tbl).

tbl contains two keys, tbl.contents and tbl.capacity

tbl.contents is another table

tbl.contents contains four keys, tbl.contents.amount, tbl.contents.name, tbl.contents.id and tbl.contents.rawName

Given this information, we can do the following:

local tbl = {contents={amount=4000.0, name=water, id=1.0,rawName=Water},capacity=4000.0}
print( "Capacity is " .. tbl.capacity )
print( "Amount is " .. tbl.contents.amount )
print( "Name is " .. tbl.contents.name )
print( "ID is " .. tbl.contents.id )
print( "Raw name is " .. tbl.contents.rawName )
Metalhawk2012 #10
Posted 27 May 2015 - 04:16 PM

that actually helped a lot i managed to get the data out the boiler and display it in the correct spot

http://www.4shared.c...0.png?lgfp=3000

but now i cant seem to loop it it will update once but then stays static.
Nevermind figured it out i put the getTankInfo() inside the loop
Edited on 27 May 2015 - 02:24 PM
Metalhawk2012 #11
Posted 27 May 2015 - 05:51 PM
Well Here it is just gotta add a few more features onto it then its fully complete
Thanks for the Help KingofGamesYami
Edited on 27 May 2015 - 05:30 PM