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

help needed on program trying to get pnumaticcraft pressure

Started by kain184, 26 June 2014 - 11:32 AM
kain184 #1
Posted 26 June 2014 - 01:32 PM
hello all i need a little help. i am trying to get computercraft to see a peripheral that is the advanced pressure valve from pnumaticcraft i am using this code

local valve = peripheral.wrap("top")
local name = peripheral.getNames()
print (name)
print(valve)
local pressure = valve.getPressure()
print(pressure)
while true do

if pressure > 5 then redstone.setOutput("top", true)
else redstone.setOutput("top", false)
end
sleep (10)
end
the problem i am getting and i don't know why from what i have looked on the forums i should be getting the output as what is inside the tables but i am getting the table names as output for example peripheral wrap is giving me output of table:73a17617 im sure the tables change per person but it should still be giving me the data inside the table not the table itself shouldn't it? if anyone can help me please let me know i'm running cc 1.63 on mc 1.6.4 with pnumaticcraft 1.1.4d
GamerNebulae #2
Posted 26 June 2014 - 02:07 PM
What is the output when you do this:

print(textutils.serialize(pressure))
kain184 #3
Posted 26 June 2014 - 02:44 PM
it says nil and than 1
GamerNebulae #4
Posted 26 June 2014 - 03:04 PM
First you say you get that the result is a table and now it's nil? Are you sure you did not make a mistake?
kain184 #5
Posted 26 June 2014 - 03:48 PM
sorry more specificly i tried it on two diffrent ones on one computer just to see if it would give a diffrence the one that is under the valve that should be connecting to the valve is giving me a nil when i go into the lua terminal and putting in the code you sent the other that was not connected is giving me a one though that one may be reading my wireless redstone connecters that are attached to it

when i use your code it gives me nil when i tell it to tell me the output of my variables it gives me a table number what i am trying to get is the number in that table that represents the pressure inside the pressure guage above it that should be called through the wraped periperal using the get pressure function that is supposed to be included with pnumaticraft
GamerNebulae #6
Posted 26 June 2014 - 04:12 PM
Let me clarify a bit. The methode I gave you, textutils.serialize(table), is a method to print out a table without a for-loop and I changed the print to print out the table in that manor. Pressure is a table you get by "asking" a peripheral called "valve" to get you the result of the method getPressure(). That appears to be a table. So if you got the variable pressure and use the code I gave you, you're set.


valve = peripheral.wrap(side) --#Please change side to the side where the peripheral is touching the computer.
print(textutils.serialze(valve.getPressure()))
kain184 #7
Posted 26 June 2014 - 04:27 PM
still getting a nil ? mark value for it even though the table shows up when i get names or tell it to print output and i have done this on one that does not have anything attached to it to make sure i dont get any response on that one and i dont.
GamerNebulae #8
Posted 26 June 2014 - 05:39 PM
I presume you mean the Advanced Pressure Gauge Tube. The problem you are thinking about is non-existent. You need to convert the redstone signal to a number. You can do this with this formula:

pressure = rs.getAnalogInput(side) / (2/3)
kain184 #9
Posted 02 July 2014 - 10:03 PM
i know i can do it that way but i was trying to use the pnumaticraft api on it to use the peripheral code
TheOddByte #10
Posted 02 July 2014 - 10:11 PM
Hey, it seems you're getting the table name because of this

local name = peripheral.getNames()
print( name )
that's because peripheral.getNames() returns a table of all peripherals attached

To add a debug to your script you should do this

print( "Pressure: " .. type( pressure ) )
to see if the pressure is a table or whatever