36 posts
Posted 10 June 2016 - 08:13 PM
I know, there are athousand threads about it but I seriously cant figure out how to do it correctly :D/>
since Iron Tanks by railcraft are currently broken ( It will always say its empty from the outside blocks, even from the valve ) I tried to use OpenBlocks tanks.
every single one of my tried ended up in errors so I dont even know how it would help describing my progress so far. :P/>
I know that "getTankInfo()" works but I cand figure out how to draw it onto a monitor / the computer screen itself.
Is there any simple way of just letting it tell how much is in the tank?
1220 posts
Location
Earth orbit
Posted 10 June 2016 - 08:26 PM
IIRC, getTankInfo() returns a table that contains the info you're looking for. This should get you started (untested)…
local tank = peripheral.wrap(<side in quotes>) --# wrap the tank as a peripheral
local tankInfo = tank.getTankInfo("unknown") --# get the tank info
local tankStats = tankInfo[1] --# store the first table returned
print tankStats.rawName --# print the raw name of the fluid in the tank
print tankStats.amount --# print the amount in the tank
print tankStats.capacity --# print the capacity of the tank
36 posts
Posted 10 June 2016 - 09:16 PM
IIRC, getTankInfo() returns a table that contains the info you're looking for. This should get you started (untested)…
local tank = peripheral.wrap(<side in quotes>) --# wrap the tank as a peripheral
local tankInfo = tank.getTankInfo("unknown") --# get the tank info
local tankStats = tankInfo[1] --# store the first table returned
print tankStats.rawName --# print the raw name of the fluid in the tank
print tankStats.amount --# print the amount in the tank
print tankStats.capacity --# print the capacity of the tank
Already tried it that way. This way it will only show the max capacity of the tanks I tried it with.
The lines with the names and the current amount will just stay empty/black which will look like this on the screen:
1 :
2 :
3: 16000
1220 posts
Location
Earth orbit
Posted 10 June 2016 - 09:48 PM
It seems the structure of the data returned has changed since I last worked with tanks. Try this and tell me what you get…
local tank = peripheral.wrap(<side in quotes>)
local tankInfo = tank.getTankInfo("unknown")
local tankStats = tankInfo[1]
for k, v in pairs(tankStats) do
print(k .. " / " .. v)
end
Edited on 10 June 2016 - 07:49 PM
36 posts
Posted 10 June 2016 - 10:00 PM
It seems the structure of the data returned has changed since I last worked with tanks. Try this and tell me what you get…
local tank = peripheral.wrap(<side in quotes>)
local tankInfo = tank.getTankInfo("unknown")
local tankStats = tankInfo[1]
for k, v in pairs(tankStats) do
print(k .. " / " .. v)
end
The answer will be like that:
capacity / 16000 – it will print the word capacity not the actual capacity
test:5: attempt to concatenate string and table – test = the name you give the program
Edited on 10 June 2016 - 08:02 PM
3057 posts
Location
United States of America
Posted 10 June 2016 - 10:08 PM
Adding a "type" will get rid of that error, while still giving you usable results.
local tank = peripheral.wrap(<side in quotes>)
local tankInfo = tank.getTankInfo("unknown")
local tankStats = tankInfo[1]
for k, v in pairs(tankStats) do
print(k .. " / " .. type( v ) )
end
<shameless self-promotion>
The final section of
my tutorial covers this.
</shameless self-promotion>
36 posts
Posted 10 June 2016 - 10:18 PM
Adding a "type" will get rid of that error, while still giving you usable results.
local tank = peripheral.wrap(<side in quotes>)
local tankInfo = tank.getTankInfo("unknown")
local tankStats = tankInfo[1]
for k, v in pairs(tankStats) do
print(k .. " / " .. type( v ) )
end
<shameless self-promotion>
The final section of
my tutorial covers this.
</shameless self-promotion>
This ends in kind of the same result.
It will just print the words themselves.
3057 posts
Location
United States of America
Posted 10 June 2016 - 10:23 PM
That was the intention, now you can inspect the contents table.
local tank = peripheral.wrap(<side in quotes>)
local tankInfo = tank.getTankInfo("unknown")
local tankStats = tankInfo[1]
for k, v in pairs(tankStats.contents) do
print(k .. " / " .. type( v ) )
end
36 posts
Posted 10 June 2016 - 10:33 PM
That was the intention, now you can inspect the contents table.
local tank = peripheral.wrap(<side in quotes>)
local tankInfo = tank.getTankInfo("unknown")
local tankStats = tankInfo[1]
for k, v in pairs(tankStats.contents) do
print(k .. " / " .. type( v ) )
end
Sorry, if im retarded or just dumb, but how does the content table help me?
1220 posts
Location
Earth orbit
Posted 10 June 2016 - 11:32 PM
As I understand it, you're interested in the amount in the tank - contents may hold that information.
36 posts
Posted 10 June 2016 - 11:40 PM
As I understand it, you're interested in the amount in the tank - contents may hold that information.
Yes, I am. But it still only prints the words themselves. :c
Not sure if its still an error on my side or if im using a bugged version
1220 posts
Location
Earth orbit
Posted 10 June 2016 - 11:49 PM
We need the words - that's telling us what is where. Please post the output of the program.
36 posts
Posted 10 June 2016 - 11:57 PM
tank without anything in it:
test:4: bad argument: table expected, got nil
tank with any fluid in it:
rawName / string
amount / number
name / string
id / number
Edited on 10 June 2016 - 10:07 PM
3057 posts
Location
United States of America
Posted 11 June 2016 - 12:31 AM
Edit: See Dog's code below
Or am I derping?
Nope, that was me.
Edited on 10 June 2016 - 10:48 PM
1220 posts
Location
Earth orbit
Posted 11 June 2016 - 12:44 AM
KingofGamesYami shouldn't that be…
local tank = peripheral.wrap(<side in quotes>)
local tankInfo = tank.getTankInfo("unknown")
local tankStats = tankInfo[1]
if not tankStats.contents then --# tankStats.contents instead of tank.contents
print( "No fluid" )
else
print( "Amount: " .. tankStats.contents.amount ) --# tankStats.contents.amount instead of tank.contents.amount
end
Or am I derping?