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

OpenCCSensors for RailCraft Tank

Started by olo2511507, 28 November 2013 - 02:56 PM
olo2511507 #1
Posted 28 November 2013 - 03:56 PM
Hello.
I need some advice, i write simple program to tinkers construct furnace, and when i pump the liquid from this furnace to a RailCraft tanks I want to know what is exactly amount liquid in this tank. When i watch some tutorials on youtube i seen that someone use sensorview to see details about the tank.But i only need amount of liquid. I open this program with notepad++ and try to get only amount data but with poor effect.
In wiki i found that simple programs:


os.loadAPI("ocs/apis/sensor")
local prox = sensor.wrap("front")
print(textutils.serialize(prox.getTargets()))

But there is no amount in there. It's only Name and position.
Can someone help me(if you understand what i write up there :D/> )

Sorry for my English :)/>
LBPHacker #2
Posted 28 November 2013 - 04:31 PM
I know nothing about Tinkers Construct, but I use OpenCCSensors a lot, and I know that sensorname.getTargets might not return every bit of information. Try sensorname.getTargetDetails(target). What I mean:
os.loadAPI("ocs/apis/sensor")
local prox = sensor.wrap("front")
for key in pairs(prox.getTargets()) do
    print(textutils.serialize(prox.getTargetDetails(key)))
end
Edited on 28 November 2013 - 03:31 PM
olo2511507 #3
Posted 28 November 2013 - 05:25 PM
Thanks a lot. I see all of the information. But I have one more question. Can I print only the "Amount" line from this Table?
I mean that in this details is the amount of this tank and i want only this value to compare(probably with "if" function) for example with the "Capacity" of the all Tank?

For Example:


if amount==8000 then
print("something")
end

Thanks for help… again :D/>
Lyqyd #4
Posted 28 November 2013 - 08:23 PM
Yeah, you just have to index the value you're interested in:


os.loadAPI("ocs/apis/sensor")
local s = sensor.wrap("front")
local details = s.getTargetDetails("tank target goes here")
print(details.Tanks[1].Amount)
olo2511507 #5
Posted 29 November 2013 - 09:01 AM
Thanks. It works perfectly :D/>
gustavowizard #6
Posted 15 May 2014 - 12:15 AM
how i set the target coordinates when its a multi-block tank? (railcraft)
Lyqyd #7
Posted 15 May 2014 - 12:54 AM
You can use sensorview to see what the coordinates are. I believe those tanks use the valve blocks as the actual "tank", each one being a mirror of all of the others on that tank.
gustavowizard #8
Posted 15 May 2014 - 06:44 AM
You can use sensorview to see what the coordinates are. I believe those tanks use the valve blocks as the actual "tank", each one being a mirror of all of the others on that tank.

oh now i can detect them on your senserview program, thanks man.

now im cracking my head here to figger why this program dont work for tanks, only for energy stuff:

os.loadAPI("ocs/apis/graph")
os.loadAPI("ocs/apis/sensor")

target = peripheral.wrap("left")
CCsensor = sensor.wrap("top")
position = "-2,-1,0"

term.clear()

function update()
local tab = sensor.call("top", "getTargetDetails", position)
return tab.Stored
end

newGraph = graph.new(target, update, "EU", nil, 0, CCsensor.getTargetDetails(position).Capacity, true)

while true do
newGraph:draw()
sleep(1)
end

any idea??
thank you again
gustavowizard #9
Posted 15 May 2014 - 06:58 AM
it give me 'graph:23: attempt to compare nil with number' error
gezepi #10
Posted 15 May 2014 - 06:59 AM
I'll go ahead and put your code in code tags since that will make it way more readable (and therefore easier to find bugs in).

os.loadAPI("ocs/apis/graph")
os.loadAPI("ocs/apis/sensor")
target = peripheral.wrap("left")
CCsensor = sensor.wrap("top")
position = "-2,-1,0"
term.clear()
function update()
  local tab = sensor.call("top", "getTargetDetails", position)
  return tab.Stored
end
newGraph = graph.new(target, update, "EU", nil, 0, CCsensor.getTargetDetails(position).Capacity, true)
while true do
  newGraph:draw()
  sleep(1)
end

Edit: Removed the bits that were making things less clear.

The error means that one of the values you are passing to graph is nil (meaning it was not loaded correctly). If you print all of these values before trying to run graph, do any of them not look like they should?
Edited on 15 May 2014 - 06:38 PM
Lyqyd #11
Posted 15 May 2014 - 07:14 AM
I appreciate the attempt to provide assistance, but your post gets a lot of things wrong in relation to the graph API and ends up being rather misleading. The sensor.call call is correct, though the wrapped peripheral replacement is also okay. peripheral.call does not work except in the very latest version (due to a recent change). Position is supposed to be passed as a string, not a table.

gustavowizard, can you provide a screenshot of sensorview showing the details for the tank at -2,-1,0?
gustavowizard #12
Posted 15 May 2014 - 07:22 AM
hey man i tested all pastebin programs on the pastebin site for monitoring tanks and guess what none of them work :(/> did CC1.6.3 change so much?) im not finding programs for it
gustavowizard #13
Posted 15 May 2014 - 07:29 AM
I appreciate the attempt to provide assistance, but your post gets a lot of things wrong in relation to the graph API and ends up being rather misleading. The sensor.call call is correct, though the wrapped peripheral replacement is also okay. peripheral.call does not work except in the very latest version (due to a recent change). Position is supposed to be passed as a string, not a table.

gustavowizard, can you provide a screenshot of sensorview showing the details for the tank at -2,-1,0?

oh sorry i change the position to test it, but the sensorview is working fine, my problem is i just want to learn the stuff and i cant find the information, because everything changed now, all the pastebin programs are not working for some reason (all that i posted here is not mine is all from there), so i have to learn so i can fix the ones i want, im trying to figger out this program up there, to display the tanks as its displaying the energy machines info. After that i think i need to learn to how make graph bars, capturing the amount data from a lot of tanks and displaying on 1 monitor, using wireless modem (like the program - that dont work now - i put on the other post)
gustavowizard #14
Posted 15 May 2014 - 07:34 AM
I'll go ahead and put your code in code tags since that will make it way more readable (and therefore easier to find bugs in).

os.loadAPI("ocs/apis/graph")
os.loadAPI("ocs/apis/sensor")
target = peripheral.wrap("left")
CCsensor = sensor.wrap("top")
position = "-2,-1,0"
term.clear()
function update()
  local tab = sensor.call("top", "getTargetDetails", position)
  return tab.Stored
end
newGraph = graph.new(target, update, "EU", nil, 0, CCsensor.getTargetDetails(position).Capacity, true)
while true do
  newGraph:draw()
  sleep(1)
end

I'm pretty sure this part
sensor.call("top", "getTargetDetails", position)
is supposed to be
peripheral.call("top", "getTargetDetails", position)


But, since you already wrapped your sensor (line 4) you can just do this
CCsensor.getTargetDetails(position)

I'm not sure how openCCSensors works exactly but you may have to pass your position in as a table (which is pretty easy)
position = {-2,-1,0}


The error means that one of the values you are passing to graph is nil (meaning it was not loaded correctly). If you print all of these values before trying to run graph, do any of them not look like they should?

thank you for assistence
run Graph? i need a program to make this all work?
Lyqyd #15
Posted 15 May 2014 - 04:02 PM
It will be easier to help you debug this if, as I requested earlier, you can provide a screenshot of sensorview showing the details for the tank you are interested in.

Please ignore gezepi's post. He made a good effort to help, but wasn't fully cognizant of the way OCS works.
gezepi #16
Posted 15 May 2014 - 08:46 PM
Yeah, I wasn't really putting two and two together to realize that this was for OCS, I had in my mind plain old peripherals. I've removed the unhelpful part of my post and will try to only provide information for things I have experience on.

gustavowizard, the error 'graph:23: attempt to compare nil with number' is from calling graph.new. One line 23 of the graph API a value that should be a number is actually a nil value. This probably means that one of the parameters on this line

newGraph = graph.new(target, update, "EU", nil, 0, CCsensor.getTargetDetails(position).Capacity, true)
is actually a nil value. Unfortunately I don't really know anything about how the graph API works so I can only say that it might be helpful to print out the parameters (such as target and update) right before you use the API. That way you'll know if any of your variables are not what you expect them to be.
gustavowizard #17
Posted 16 May 2014 - 03:13 AM
It will be easier to help you debug this if, as I requested earlier, you can provide a screenshot of sensorview showing the details for the tank you are interested in.

Please ignore gezepi's post. He made a good effort to help, but wasn't fully cognizant of the way OCS works.

Thank you both of you
, im having trouble to upload the picture here, but its on my Flick album, the first picture:

https://www.flickr.com/photos/121771033@N05/with/14195608345/

its a railcraft steel tank, on sensorview program. What i want to learn is simple how to just show 1 tab(atribute) like Amount, on a % bar, like this guy here did:

https://www.youtube.com/watch?v=wFVr7JuDijQ

and his programs:
http://pastebin.com/mYmZpBxr
http://pastebin.com/kryRY8UK

thanks help again man
Lyqyd #18
Posted 16 May 2014 - 03:41 AM
You were trying to index the value incorrectly. There isn't a Capacity variable in the main table it returns, you have to pull it from the individual tank table in the Tanks table. I adjusted the two places you had it wrong and updated the location to match the one in your screenshot:


os.loadAPI("ocs/apis/graph")
os.loadAPI("ocs/apis/sensor")

target = peripheral.wrap("left")
CCsensor = sensor.wrap("top")
position = "-3,1,-3"

term.clear()

function update()
    local tab = sensor.call("top", "getTargetDetails", position)
    return tab.Tanks[1].Stored
end

newGraph = graph.new(target, update, "EU", nil, 0, CCsensor.getTargetDetails(position).Tanks[1].Capacity, true)

while true do
    newGraph:draw()
    sleep(1)
end

I'm not sure why you're calling the liquid "EU", but that's okay!

If you're wanting help with the other code you posted, you'll have to specify what problems you're having with it and post any error messages. First, though, give that code above a try.
gustavowizard #19
Posted 16 May 2014 - 05:54 AM
i tried that code it still gives me error on the big line (15):

'tanks:15: attempt to index? (a nil value)'
apemanzilla #20
Posted 16 May 2014 - 04:56 PM
I'm guessing that it's either A. not finding the tank, or B. not finding the capacity of the tank. More likely A.
Edited on 16 May 2014 - 02:56 PM
gustavowizard #21
Posted 17 May 2014 - 01:49 AM
I'm guessing that it's either A. not finding the tank, or B. not finding the capacity of the tank. More likely A.

hum might be something like B cause when i use this same come, but for Energy of MSFU and other energy IC2 stuff it works. And the Lyqyd program sensorview does detect the tanks, for some reason, on that code, i miss something to make it work on tanks of any kind, im betting on those atributes, the API of openccsensors recognize the right names for each instance (Stored, MaxHeat) so i guess i need the right 'word' for calling the tank Amount / Capacity to show like a graph bar with a %
gustavowizard #22
Posted 19 May 2014 - 01:52 AM
strange sometime sensorview stop workign on railcraft tanks, dunno if have something to do with the pipes of buildcraft
gustavowizard #23
Posted 19 May 2014 - 04:59 AM
yeah i figured it out, its the buildcraft pipes man, when they are on the range of the sensor, at the same time it also detecting a railcraft tank, it crashes the CC computer, so using a Mk II sensor with a smaller range i could get it with no problem, just need to to learn to code to how to do it myself now. just giving you a heads up of this 'bug' ;)/>
gustavowizard #24
Posted 23 May 2014 - 12:38 PM
still i could use some help to make that 1 simple program i posted work on a tank, the code Lyqyd passed me still not working, thanks thou
gustavowizard #25
Posted 30 May 2014 - 11:21 PM
You were trying to index the value incorrectly. There isn't a Capacity variable in the main table it returns, you have to pull it from the individual tank table in the Tanks table. I adjusted the two places you had it wrong and updated the location to match the one in your screenshot:


os.loadAPI("ocs/apis/graph")
os.loadAPI("ocs/apis/sensor")

target = peripheral.wrap("left")
CCsensor = sensor.wrap("top")
position = "-3,1,-3"

term.clear()

function update()
	local tab = sensor.call("top", "getTargetDetails", position)
	return tab.Tanks[1].Stored
end

newGraph = graph.new(target, update, "EU", nil, 0, CCsensor.getTargetDetails(position).Tanks[1].Capacity, true)

while true do
	newGraph:draw()
	sleep(1)
end

I'm not sure why you're calling the liquid "EU", but that's okay!

If you're wanting help with the other code you posted, you'll have to specify what problems you're having with it and post any error messages. First, though, give that code above a try.

i got graph:23: attemp to compare nil with number with this
gustavowizard #26
Posted 30 May 2014 - 11:29 PM
Jeeeez i finalyl found the error! Tanks use AMOUNT not STORED :D/>
i just replaced that 'return.tab.Tanks[1].Stored to Amunt' finaly! lol