Jump to content




[MC 1.7.10 | CC 1.65] OpenCCSensors

lua

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

#721 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 25 February 2013 - 01:02 PM

Okay, let's try the same script again, except replace this line:

local targets = sens.getTargets()

with these two lines:

local targets, err = sens.getTargets()
if err then print("Error: "..tostring(err)) return end

Only the sonic sensor output is needed this time.

#722 TheGeek

  • Members
  • 60 posts

Posted 25 February 2013 - 02:35 PM

View PostLyqyd, on 25 February 2013 - 01:02 PM, said:

Okay, let's try the same script again, except replace this line:

local targets = sens.getTargets()

with these two lines:

local targets, err = sens.getTargets()
if err then print("Error: "..tostring(err)) return end

Only the sonic sensor output is needed this time.

Same output as before:
Sensor found on top side.
Sensor type is: openccsensors.item.sonicsensor

No error generated.

Edited by TheGeek, 25 February 2013 - 02:37 PM.


#723 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 25 February 2013 - 04:20 PM

Hmm. Just for fun, throw an `error = print` just before the getTargets line. This is looking like more and more of a sonic sensor issue, though. If it is an issue intrinsic to the sonic sensor, I'm not set up to work on the Java side of things.

#724 immibis

    Lua God

  • Members
  • 1,033 posts
  • LocationWellington, New Zealand

Posted 25 February 2013 - 04:42 PM

View PostLyqyd, on 25 February 2013 - 01:02 PM, said:

Okay, let's try the same script again, except replace this line:

local targets = sens.getTargets()

with these two lines:

local targets, err = sens.getTargets()
if err then print("Error: "..tostring(err)) return end

Only the sonic sensor output is needed this time.

Did you mean to use pcall?

#725 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 25 February 2013 - 07:33 PM

View Postimmibis, on 25 February 2013 - 04:42 PM, said:

View PostLyqyd, on 25 February 2013 - 01:02 PM, said:

Okay, let's try the same script again, except replace this line:

local targets = sens.getTargets()

with these two lines:

local targets, err = sens.getTargets()
if err then print("Error: "..tostring(err)) return end

Only the sonic sensor output is needed this time.

Did you mean to use pcall?

You have a very valid point--pcall is the correct thing to use in relation to the existing sensor API code. The method I suggested in the quoted post would work for the error handling method the team had discussed changing to but apparently never actually went to--returning nil, "error message". Given that it is error()ing though, I would have thought to expect printError() output from os.run after it errored, so I suspect a nil or empty error string is being thrown out by the sonic sensor.

#726 TheGeek

  • Members
  • 60 posts

Posted 26 February 2013 - 03:10 PM

View PostLyqyd, on 25 February 2013 - 04:20 PM, said:

Hmm. Just for fun, throw an `error = print` just before the getTargets line. This is looking like more and more of a sonic sensor issue, though. If it is an issue intrinsic to the sonic sensor, I'm not set up to work on the Java side of things.

No change in output. I am using ConstructionFoam from IndustrialCraft, would a non-vanilla block perhaps be interfering with the operation?

#727 ihatetn931

  • Members
  • 75 posts
  • LocationCookeville, Tn

Posted 26 February 2013 - 03:37 PM

I'm trying to learn lua, does anyone happen to know where i can find somewhere on how to use the graph api, i've been trying to figure it out and i can't, some code examples will be nice, i looked at the one on the op and it really didn't help me any. I'm trying to implant it in to a code that was posted on this topic.

#728 jewelshisen

  • Members
  • 164 posts

Posted 26 February 2013 - 04:32 PM

Hit a problem. Have an Adv. Comp with a sensor on top. However when I pull up the program list the sensorview doesn't come up. I replaced my OCS folder and it still wont work.

#729 Kye_Duo

  • Members
  • 70 posts

Posted 26 February 2013 - 04:34 PM

View Postjewelshisen, on 26 February 2013 - 04:32 PM, said:

Hit a problem. Have an Adv. Comp with a sensor on top. However when I pull up the program list the sensorview doesn't come up. I replaced my OCS folder and it still wont work.
are you in the right folder? its under the ocs/programs folder, not the main folder

#730 jewelshisen

  • Members
  • 164 posts

Posted 26 February 2013 - 04:44 PM

View PostKye_Duo, on 26 February 2013 - 04:34 PM, said:

View Postjewelshisen, on 26 February 2013 - 04:32 PM, said:

Hit a problem. Have an Adv. Comp with a sensor on top. However when I pull up the program list the sensorview doesn't come up. I replaced my OCS folder and it still wont work.
are you in the right folder? its under the ocs/programs folder, not the main folder

Yea it is there in the ocs/programs folder but it has always shown up in the main program list as well.

#731 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 27 February 2013 - 06:32 AM

View Postihatetn931, on 26 February 2013 - 03:37 PM, said:

I'm trying to learn lua, does anyone happen to know where i can find somewhere on how to use the graph api, i've been trying to figure it out and i can't, some code examples will be nice, i looked at the one on the op and it really didn't help me any. I'm trying to implant it in to a code that was posted on this topic.

What are you having problems with, specifically? The example code is a relatively simple case. Do you have any (even non-working) code? Seeing what you're working with will help to know what you need help with.

View Postjewelshisen, on 26 February 2013 - 04:32 PM, said:

Hit a problem. Have an Adv. Comp with a sensor on top. However when I pull up the program list the sensorview doesn't come up. I replaced my OCS folder and it still wont work.

Have you tried running `ocs/programs/sensorview`, regardless of it not being present in the output of the programs program?

#732 ihatetn931

  • Members
  • 75 posts
  • LocationCookeville, Tn

Posted 27 February 2013 - 07:03 AM

I kinda got it figured out how it works, the only problem i'm having is it's not updating, I tried the update function on this topic and it didn't work it kept giving a nil value this is what I came up with. Is there a way to get multiple graphs on 1 monitor or do they need to be on seprate ones. Also is there a way to go to a new line?

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

local sensor = sensor.wrap("right")
local details = sensor.getTargetDetails("1,1,0")

function update()
  return (peripheral.call("right","getTargetDetails",reactor))
end

graphInst = graph.new(peripheral.wrap("top"), update,"Temp "..details.Heat,nil,1,108000,true)
graphInst:draw()
end


#733 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 27 February 2013 - 07:50 AM

Don't sensor.wrap into a variable named sensor, you'll override the sensor API (this is bad). Use sensor.call instead of peripheral.call. You haven't defined "reactor", so you're passing it a nil target to get information from. You're returning the whole table given by getTargetDetails in your update function; you need to return a single value from it. Multiple graphs on one monitor is certainly possible (it's a built in feature of the API). There's a post several pages back that explains the multiple graph usage better. If you can't find it, I'll poke around and look for the link to it.

#734 ihatetn931

  • Members
  • 75 posts
  • LocationCookeville, Tn

Posted 27 February 2013 - 08:06 AM

I'm not really sure, I changed it to sensor.call, the reactor thing was something I forgot to change before I pasted it, I was teaching myself variables with it. I changed the code a little bit
 
os.loadAPI("ocs/apis/graph")
os.loadAPI("ocs/apis/sensor")

local mon = peripheral.wrap("top")
local reactorsensor1 = "right"
local reactor1 = "1,1,0"
local getdetails = "getTargetDetails"

function update()
	local tab = (sensor.call( reactorsensor1 , getdetails , reactor1))
	return tab.Stored
 end

graphInst = graph.new(mon , update , "Heat " , 1 , 0 , 108000 , false)
graphInst:draw()

I get this error which comes from line 20 of the graph api. This is why I changed it peripheral.call cause I kept getting this error and with me being new in lua I didn't know how to fix it
 graph:20: attempt to compare table with number 
If needed line 20 of graph
 if self.history[trace][#self.history[trace]] > self.max[trace] then 
I'll have a look back to see if I can find the multi graph.

Edit: Found the multi-graph, thanks.

#735 jewelshisen

  • Members
  • 164 posts

Posted 27 February 2013 - 08:34 PM

View PostLyqyd, on 27 February 2013 - 06:32 AM, said:

-snip-

View Postjewelshisen, on 26 February 2013 - 04:32 PM, said:

Hit a problem. Have an Adv. Comp with a sensor on top. However when I pull up the program list the sensorview doesn't come up. I replaced my OCS folder and it still wont work.

Have you tried running `ocs/programs/sensorview`, regardless of it not being present in the output of the programs program?

Yes and that does work but I am just confused as to why the change.

#736 The Geek

  • Members
  • 13 posts
  • LocationDIM0

Posted 28 February 2013 - 03:35 AM

Hi all, im fiddling around with a world detector card and a program to trigger a RS signal if Rain / Daytime is detected. So far im unable to get it to work because i always get a "attempt to concatenate string and nil" error. Here is what works printing out the "name" of the world:

os.loadAPI("ocs/apis/sensor")
local prox = sensor.wrap("back")
local targets = prox.getTargets()
for name, details in pairs(targets) do
  print("Raining: " ..details["Name"])
end

what does not work is getting thew world information on "Raining" and "Daytime". I would really appreciate a pointer into the right direction.

#737 ihatetn931

  • Members
  • 75 posts
  • LocationCookeville, Tn

Posted 28 February 2013 - 06:27 AM

Ok, I got that issue fixed and the code is working but it's still not updating, do I need some type of timer to update it, if so how do I do a timer?

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

local mon = peripheral.wrap("top")
local reactorsensor1 = "right"
local reactor1 = "1,1,0"
local getdetails = "getTargetDetails"

function update()
	local tab = sensor.call(reactorsensor1, getdetails , reactor1)
	return tab.Heat
end

graphInst = graph.new(mon , update,"Heat",  nil , 1  , 10800)
graphInst:draw()


#738 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 28 February 2013 - 06:39 AM

Yeah, I usually do something like:

while true do
  graphInst:draw()
  sleep(0.5)
end


#739 ihatetn931

  • Members
  • 75 posts
  • LocationCookeville, Tn

Posted 28 February 2013 - 06:53 AM

Sweet thanks, sorry to be a bother, I might have more questions down the road.

Thanks again

#740 The Geek

  • Members
  • 13 posts
  • LocationDIM0

Posted 28 February 2013 - 10:52 AM

...still looking for help with the above problem ;/





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users