Jump to content




Tank Level monitoring


  • You cannot reply to this topic
14 replies to this topic

#1 Obsidia

  • Members
  • 36 posts

Posted 10 June 2016 - 07: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?

#2 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 10 June 2016 - 07: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


#3 Obsidia

  • Members
  • 36 posts

Posted 10 June 2016 - 08:16 PM

View PostDog, on 10 June 2016 - 07:26 PM, said:

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

#4 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 10 June 2016 - 08: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 by Dog, 10 June 2016 - 08:49 PM.


#5 Obsidia

  • Members
  • 36 posts

Posted 10 June 2016 - 09:00 PM

View PostDog, on 10 June 2016 - 08:48 PM, said:

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 by Obsidia, 10 June 2016 - 09:02 PM.


#6 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 10 June 2016 - 09: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>

#7 Obsidia

  • Members
  • 36 posts

Posted 10 June 2016 - 09:18 PM

View PostKingofGamesYami, on 10 June 2016 - 09:08 PM, said:

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.

Posted Image

Posted Image

It will just print the words themselves.

#8 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 10 June 2016 - 09: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


#9 Obsidia

  • Members
  • 36 posts

Posted 10 June 2016 - 09:33 PM

View PostKingofGamesYami, on 10 June 2016 - 09:23 PM, said:

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?

#10 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 10 June 2016 - 10:32 PM

As I understand it, you're interested in the amount in the tank - contents may hold that information.

#11 Obsidia

  • Members
  • 36 posts

Posted 10 June 2016 - 10:40 PM

View PostDog, on 10 June 2016 - 10:32 PM, said:

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

#12 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 10 June 2016 - 10:49 PM

We need the words - that's telling us what is where. Please post the output of the program.

#13 Obsidia

  • Members
  • 36 posts

Posted 10 June 2016 - 10: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 by Obsidia, 10 June 2016 - 11:07 PM.


#14 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 10 June 2016 - 11:31 PM

Edit: See Dog's code below

View PostDog, on 10 June 2016 - 11:44 PM, said:

Or am I derping?

Nope, that was me.

Edited by KingofGamesYami, 10 June 2016 - 11:48 PM.


#15 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 10 June 2016 - 11:44 PM

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?





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users