Jump to content




[MC 1.7.10 | CC 1.65] OpenCCSensors

lua

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

#741 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 28 February 2013 - 11:16 AM

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"])
  for k, v in pairs(prox.getTargetDetails(name)) do
    print(tostring(k)..": "..tostring(v))
  end
end


#742 tabs

  • Members
  • 21 posts

Posted 01 March 2013 - 02:55 AM

Did a barrels fix make it into the latest version?

#743 The Geek

  • Members
  • 13 posts
  • LocationDIM0

Posted 01 March 2013 - 03:52 AM

Lyquyd: Thanks for the code, this seems to work flawlessly listing all values the sensor offers. However i'm trying to just get True or False out of "Raining" and "Daytime". Being the lua-newbie i tried this:
print(tostring(targets[0]))
or
print(tostring(targets.Raining))
to see if i can reference just that specific value im looking for but alas... no workie ;/

Now, i briefly looked at a couple of lua table tutorials on the net but cant really wrap my head around what kind of table and contents OCS exposes and how i can extract exactly those values im looking for.

Any help - again - is appreciated !!!

#744 ihatetn931

  • Members
  • 75 posts
  • LocationCookeville, Tn

Posted 01 March 2013 - 04:07 AM

Thought I would share this, it's my very first program.

It shows the temp on the graph, if the temp is above 3000 it sends a bundled cable output and turns the reactor off then when the temp hits 1000 it turns the reactor back on. You can change them by changing the value on MaxTemp and LowestTemp

Spoiler


#745 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 01 March 2013 - 04:20 AM

View PostThe Geek, on 01 March 2013 - 03:52 AM, said:

Lyquyd: Thanks for the code, this seems to work flawlessly listing all values the sensor offers. However i'm trying to just get True or False out of "Raining" and "Daytime". Being the lua-newbie i tried this:
print(tostring(targets[0]))
or
print(tostring(targets.Raining))
to see if i can reference just that specific value im looking for but alas... no workie ;/

Now, i briefly looked at a couple of lua table tutorials on the net but cant really wrap my head around what kind of table and contents OCS exposes and how i can extract exactly those values im looking for.

Any help - again - is appreciated !!!

Well, the raining and daytime values are (I believe) in the target details table. Last time I used the world sensor, there was only one target, named CURRENT. So you would use something vaguely thus:

local details = sensor.call("top", "getTargetDetails", "CURRENT")
if details.Raining then
  --it is raining.
end


#746 RicardoRedstone

  • Members
  • 6 posts
  • LocationBrazil

Posted 01 March 2013 - 05:37 AM

what about adding creative-only any range sensor(you could specify it on gui, no limits)

#747 The Geek

  • Members
  • 13 posts
  • LocationDIM0

Posted 01 March 2013 - 05:44 AM

@Lygyd: Thanks for the tips! I guess the best thing would be to have an API for OpenCCSensors so one knows what is stored where and how to access the information.

Here is what i came up with now:
os.loadAPI("ocs/apis/sensor")
local sns = sensor.wrap("back")

-- print table data func
function prTBL(data)
  for i,v in pairs(data) do
	print(tostring(i).." - "..tostring(v))
  end
end

term.clear()
term.setCursorPos(1,1)
print("---------------------------------")
prTBL(sns.getTargetDetails("CURRENT"))
print("---------------------------------")
local data=sns.getTargetDetails("CURRENT")
print("Biome: "..tostring(data.Biome))
print("---------------------------------")

if data.Raining then
  print("It's raining!")
end

if data.Daytime then
  print("It's daytime!")
end


#748 ihatetn931

  • Members
  • 75 posts
  • LocationCookeville, Tn

Posted 01 March 2013 - 05:58 AM

View PostThe Geek, on 01 March 2013 - 05:44 AM, said:

@Lygyd: That snippet of code does not work, "attempt to call nil". I guess the best thing would be to have an API for OpenCCSensors so one knows what is stored where and how to access the information. Still fiddling around with this...

I agree, having to check sensorview to get the name to pull the info can be a pain, esp if you're new and don't know it all. Should be some place where it shows what you can pull from each sensor like if you wanna pull heat then you need to do Variable.Heat, it took me for ever to figure out how they where getting the info but I have caught on to but I still need to check sensor view to get it.

This is the info from the world sensor, for the x y z it uses CURRENT unlike the others that use x y z

RawName> world
Raining> false
Name> World
Thundering> false
Biome> DesertHills
LightLevel> 15
Dimension> 0
Daytime> true


#749 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 01 March 2013 - 10:16 AM

View PostRicardoRedstone, on 01 March 2013 - 05:37 AM, said:

what about adding creative-only any range sensor(you could specify it on gui, no limits)

Sorry, no - this would cause far too much server lag.

View Postihatetn931, on 01 March 2013 - 05:58 AM, said:

View PostThe Geek, on 01 March 2013 - 05:44 AM, said:

@Lygyd: That snippet of code does not work, "attempt to call nil". I guess the best thing would be to have an API for OpenCCSensors so one knows what is stored where and how to access the information. Still fiddling around with this...

I agree, having to check sensorview to get the name to pull the info can be a pain, esp if you're new and don't know it all. Should be some place where it shows what you can pull from each sensor like if you wanna pull heat then you need to do Variable.Heat, it took me for ever to figure out how they where getting the info but I have caught on to but I still need to check sensor view to get it.

This is the info from the world sensor, for the x y z it uses CURRENT unlike the others that use x y z

RawName> world
Raining> false
Name> World
Thundering> false
Biome> DesertHills
LightLevel> 15
Dimension> 0
Daytime> true

This is what /ocs/programs/sensorview is for

#750 ihatetn931

  • Members
  • 75 posts
  • LocationCookeville, Tn

Posted 01 March 2013 - 05:23 PM

possible to change the text scale with the graph?

#751 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 02 March 2013 - 11:22 AM

View Postihatetn931, on 01 March 2013 - 05:23 PM, said:

possible to change the text scale with the graph?

Yes, but increasing the text scale also decreases the resolution of the traces. Everything on a monitor must use the same scale. If you still wish to increase the scale of the text and the graph traces, simply copy ocs/apis/graph and modify the copy to use a different scale. Look for setTextScale in the draw function. It is currently 0.5.

We will not be increasing the scale in the mod's version of that API.

#752 Kye_Duo

  • Members
  • 70 posts

Posted 02 March 2013 - 11:38 AM

I'd so love an IC2 crop sensor...I wouldn't care if it just sensed weeds...though I'd prefer some more info than that...maybe growth stage and name of crop, (stats would be nice too but I wouldn't turn down one that could get the stats as well)

#753 pojx

  • New Members
  • 1 posts
  • LocationGermany

Posted 09 March 2013 - 08:34 AM

Didn't find any suggestion like mine : Whats about a Universal Electricity Sensor?

#754 Watchful11

  • Members
  • 8 posts

Posted 11 March 2013 - 11:39 AM

Got a bug to report.

If redpower is installed, the Sonic Sensor card mk4 returns a "ocs_error" after being called with getTargets. Well, technically the event it throws has "ocs_error" in the first field and the 3rd field is nil, but you know what I mean. This does not happen without redpower. I have tested a few other sensor cards, including lower levels of Sonic Sensor, and they work fine, but I haven't checked all of them.
Reproduced with,
Forge 6.6.2.534
Computercraft 1.5
OpenCCsensors 0.1.4
Redpower 2.0pr6

Apparently, computercraft error handling fails silently on a error message of nil. So whatever program you are running just terminates without an error in this case. I would recommend adding a condition in waitForResponse() for nil events.

#755 Kye_Duo

  • Members
  • 70 posts

Posted 11 March 2013 - 11:49 AM

View PostWatchful11, on 11 March 2013 - 11:39 AM, said:

Got a bug to report.

If redpower is installed, the Sonic Sensor card mk4 returns a "ocs_error" after being called with getTargets. Well, technically the event it throws has "ocs_error" in the first field and the 3rd field is nil, but you know what I mean. This does not happen without redpower. I have tested a few other sensor cards, including lower levels of Sonic Sensor, and they work fine, but I haven't checked all of them.
Reproduced with,
Forge 6.6.2.534
Computercraft 1.5
OpenCCsensors 0.1.4
Redpower 2.0pr6

Apparently, computercraft error handling fails silently on a error message of nil. So whatever program you are running just terminates without an error in this case. I would recommend adding a condition in waitForResponse() for nil events.
I too am using RP2 and was getting that behavior out of the sonic sensors....I didn't think to test it without RP2...though with us all the levels do this...

#756 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 11 March 2013 - 12:06 PM

Thanks for the report guys.

#757 abihoooo

  • Members
  • 33 posts
  • LocationForge World

Posted 11 March 2013 - 12:20 PM

On my server, whenever a buildcraft sensor reads a redstone energy cell from Thermal Expansion it outputs "[INFO] [STDOUT] tileClass = thermalexpansion.energy.tileentity.TileEnergyCell" to the server console. I'm assuming it's not supposed to happen since it's the only thing spamming the server log.

#758 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 11 March 2013 - 01:13 PM

View Postabihoooo, on 11 March 2013 - 12:20 PM, said:

On my server, whenever a buildcraft sensor reads a redstone energy cell from Thermal Expansion it outputs "[INFO] [STDOUT] tileClass = thermalexpansion.energy.tileentity.TileEnergyCell" to the server console. I'm assuming it's not supposed to happen since it's the only thing spamming the server log.

Yup already been reported - will be fixed in the next release (will release in the next week). No new features for this release, just stability/bug fixes

#759 CoolisTheName007

  • Members
  • 304 posts

Posted 11 March 2013 - 11:12 PM

View PostKye_Duo, on 11 March 2013 - 11:49 AM, said:

View PostWatchful11, on 11 March 2013 - 11:39 AM, said:

Got a bug to report.

If redpower is installed, the Sonic Sensor card mk4 returns a "ocs_error" after being called with getTargets. Well, technically the event it throws has "ocs_error" in the first field and the 3rd field is nil, but you know what I mean. This does not happen without redpower. I have tested a few other sensor cards, including lower levels of Sonic Sensor, and they work fine, but I haven't checked all of them.
Reproduced with,
Forge 6.6.2.534
Computercraft 1.5
OpenCCsensors 0.1.4
Redpower 2.0pr6

Apparently, computercraft error handling fails silently on a error message of nil. So whatever program you are running just terminates without an error in this case. I would recommend adding a condition in waitForResponse() for nil events.
I too am using RP2 and was getting that behavior out of the sonic sensors....I didn't think to test it without RP2...though with us all the levels do this...

I'll look into it asap. A world save would also help.

#760 Kye_Duo

  • Members
  • 70 posts

Posted 12 March 2013 - 12:34 AM

View PostCoolisTheName007, on 11 March 2013 - 11:12 PM, said:


I'll look into it asap. A world save would also help.
what is a world save? are you talking about the server map? cause the one I'm on has quite a few mods...and I'm expecting it to grow (TOO...MANY...MODS)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users