Jump to content




help needed on program trying to get pnumaticcraft pressure

peripheral computer api

9 replies to this topic

#1 kain184

  • Members
  • 72 posts

Posted 26 June 2014 - 12: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

#2 GamerNebulae

  • Members
  • 216 posts
  • LocationNetherlands

Posted 26 June 2014 - 01:07 PM

What is the output when you do this:
print(textutils.serialize(pressure))


#3 kain184

  • Members
  • 72 posts

Posted 26 June 2014 - 01:44 PM

it says nil and than 1

#4 GamerNebulae

  • Members
  • 216 posts
  • LocationNetherlands

Posted 26 June 2014 - 02: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?

#5 kain184

  • Members
  • 72 posts

Posted 26 June 2014 - 02: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

#6 GamerNebulae

  • Members
  • 216 posts
  • LocationNetherlands

Posted 26 June 2014 - 03: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()))


#7 kain184

  • Members
  • 72 posts

Posted 26 June 2014 - 03: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.

#8 GamerNebulae

  • Members
  • 216 posts
  • LocationNetherlands

Posted 26 June 2014 - 04: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)


#9 kain184

  • Members
  • 72 posts

Posted 02 July 2014 - 09: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

#10 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

Posted 02 July 2014 - 09: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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users