Jump to content




[MC 1.7.10 | CC 1.65] OpenCCSensors

lua

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

#701 abihoooo

  • Members
  • 33 posts
  • LocationForge World

Posted 19 February 2013 - 06:43 PM

Whenever I start my SSP world my startup programs always crash the first time because it cannot find the sensor API file at world load. Is there any way around this?

#702 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 19 February 2013 - 10:01 PM

View Postabihoooo, on 19 February 2013 - 06:43 PM, said:

Whenever I start my SSP world my startup programs always crash the first time because it cannot find the sensor API file at world load. Is there any way around this?

It should always find the API - can I see one of your programs?

#703 TheGeek

  • Members
  • 60 posts

Posted 20 February 2013 - 04:31 AM

View PostMikeemoo, on 19 February 2013 - 10:01 PM, said:

View Postabihoooo, on 19 February 2013 - 06:43 PM, said:

Whenever I start my SSP world my startup programs always crash the first time because it cannot find the sensor API file at world load. Is there any way around this?

It should always find the API - can I see one of your programs?
I came across this myself once, but it was caused by having multiple sensors on one peripheral cable. The folders got misnamed; "ocs2" "ocs3" where it should have been "ocs" and "ocs2". I don't think that OCS here was at fault, but it caused my program to give a "file not found" message, for obvious reasons.

#704 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 20 February 2013 - 05:34 AM

Some exciting news about OpenCCSensors:

http://www.technicpack.net/modsafari/

#705 abihoooo

  • Members
  • 33 posts
  • LocationForge World

Posted 20 February 2013 - 08:08 AM

I'm using peripheral cables, so that may be the problem, but here is the program. It says file not found whenever it auto-starts up, then errors on the first sensor.wrap .

http://pastebin.com/DH3KE4Yj

#706 CubeCat

  • Members
  • 7 posts

Posted 21 February 2013 - 05:59 PM

For first - tnx to Mikeemoo again for help with understood item detector sensor. But now i need help with proximity. :( I understand how to get and compare all TargetDetais() but i cannot understand how to get x,y,z coords and how output them to locals. So... I will be very grateful if u can gimme a simple example program wich can detect player in specific coord and output redsignal for example.

#707 tabs

  • Members
  • 21 posts

Posted 22 February 2013 - 09:49 AM

x,y,z are stored in a table called Position if I recall correctly. Their key names are X Y and Z (use capitals).

-- you need to wrap your sensor object first
-- also assign the name of the entity (your MC user name for example)

details = sensor.getTargetDetails(entityName)

-- one way to get them out of the target details table:
local posX = details.Position.X
local posY = details.Position.Y
local posZ = details.Position.Z

-- alternatively:
local posX,posY,posZ = details.Position -- should work

If you're unsure about wrapping peripherals or outputting redstone signals you really need to be looking at the documentation and learning from that as your first port of call. For that stuff we'll only repeat the info that is already readily available to you.

#708 CubeCat

  • Members
  • 7 posts

Posted 22 February 2013 - 01:38 PM

View Posttabs, on 22 February 2013 - 09:49 AM, said:

x,y,z are stored in a table called Position if I recall correctly. Their key names are X Y and Z (use capitals).

-- you need to wrap your sensor object first
-- also assign the name of the entity (your MC user name for example)

details = sensor.getTargetDetails(entityName)

-- one way to get them out of the target details table:
local posX = details.Position.X
local posY = details.Position.Y
local posZ = details.Position.Z

-- alternatively:
local posX,posY,posZ = details.Position -- should work

If you're unsure about wrapping peripherals or outputting redstone signals you really need to be looking at the documentation and learning from that as your first port of call. For that stuff we'll only repeat the info that is already readily available to you.

Nah, nah, nah i know about wrapping and outputting. Tnx for explaining about coords!

os.loadAPI("ocs/apis/sensor")
local invent = sensor.wrap("top")
while true do
details = invent.getTargetDetails("Cat")
local posX = details.Position.X
local posY = details.Position.Y
local posZ = details.Position.Z
print("Position X:", posX)
print("Position Y:", posY)
print("Position Z:", posZ)
if posZ >=-3 and posZ <=3 and posX >=-3 and posX <=3 and posY >=-3 and posY <=3 then
  redstone.setOutput("left", true)
else
  redstone.setOutput("left", false)
end
sleep(0.2)
end

But when i run far away i got

prox:5: attempt to index ? (a nil value)

I think i must add some condition wich will track if player "Cat" in range and then gets position. But i cant realize how. :D I'm suck at coding :'(

#709 tabs

  • Members
  • 21 posts

Posted 23 February 2013 - 04:59 AM

Yes, when you leave the area you're attempting to retrieve details from a key (the entity name) that no longer exists in the table.

Perhaps a simple:
details = invent.getTargetDetails("Cat")
if details == nil then return

I'm not really up to speed on lua yet, but perhaps this will also work:
if not details then return


#710 Kye_Duo

  • Members
  • 70 posts

Posted 23 February 2013 - 05:49 AM

I have a few questions regarding the sonic sensor
1. I can't get it to work with the sensorview program, is this a bug or can it not work with that program?
2. Can it detect liquids through a block or two? I'm trying to help setup a sensor that can detect when its safe to raise a piston that is being used to create a pit under a lava fall to prevent the lava from spreading all over the place and lava is notorious for not taking the same amount of time to completely drop from the ceiling once the fall has been shut off.

#711 CubeCat

  • Members
  • 7 posts

Posted 23 February 2013 - 09:21 AM

View Posttabs, on 23 February 2013 - 04:59 AM, said:

Yes, when you leave the area you're attempting to retrieve details from a key (the entity name) that no longer exists in the table.

Perhaps a simple:
details = invent.getTargetDetails("Cat")
if details == nil then return

I'm not really up to speed on lua yet, but perhaps this will also work:
if not details then return

Ummm thats stops program... But u help me with condition :) Ure my savior :D I did like that:

os.loadAPI("ocs/apis/sensor")
local invent = sensor.wrap("top")
local monitor = peripheral.wrap("right")
while true do
details = invent.getTargetDetails("Cat")
if details == nil then
repeat
details = invent.getTargetDetails("Cat")
sleep(0.5)
until details ~= nil
else
local posX = details.Position.X
local posY = details.Position.Y
local posZ = details.Position.Z
print("Position X:", posX)
print("Position Y:", posY)
print("Position Z:", posZ)
if posZ >=-3 and posZ <=3 and posX >=-3 and posX <=3 and posY >=-3 and posY <=3 then
  redstone.setOutput("left", true)
else
  redstone.setOutput("left", false)
  end
end
sleep(0.2)
end

Is here any of huge mistakes wich can do memory leak or some?)

#712 CoolisTheName007

  • Members
  • 304 posts

Posted 23 February 2013 - 12:17 PM

View PostKye_Duo, on 23 February 2013 - 05:49 AM, said:

I have a few questions regarding the sonic sensor
1. I can't get it to work with the sensorview program, is this a bug or can it not work with that program?
2. Can it detect liquids through a block or two? I'm trying to help setup a sensor that can detect when its safe to raise a piston that is being used to create a pit under a lava fall to prevent the lava from spreading all over the place and lava is notorious for not taking the same amount of time to completely drop from the ceiling once the fall has been shut off.
I made the sonic sensor card, so:
About 1. : the sonic sensor has many targets (all blocks visible, for a certain definition of 'visible'); sensorview call getTargetsDetails for each, which results in no new intel, but each call takes a tick, so there should be some lag. That's my first attempt at an explanation.
About 2: due to the compact way I implemented it, diagonals are always visible (e.g. (1,1,1) ). So you could check for those, e.g.: wrapped_sensor.getTargetDetails()['1,1,1'] , and still the sensor wouldn't be touching lava. But they are lava-resistant, right? So I guess you want the sensor to be invisible.
It is interesting to let them have a certain see-through power, more than the accidental one, maybe based on the sensor upgrade level.
Also, what do you think about distinguishing between lava and water?

#713 Kye_Duo

  • Members
  • 70 posts

Posted 24 February 2013 - 02:53 AM

Quote

I made the sonic sensor card, so:
About 1. : the sonic sensor has many targets (all blocks visible, for a certain definition of 'visible'); sensorview call getTargetsDetails for each, which results in no new intel, but each call takes a tick, so there should be some lag. That's my first attempt at an explanation.
About 2: due to the compact way I implemented it, diagonals are always visible (e.g. (1,1,1) ). So you could check for those, e.g.: wrapped_sensor.getTargetDetails()['1,1,1'] , and still the sensor wouldn't be touching lava. But they are lava-resistant, right? So I guess you want the sensor to be invisible.
It is interesting to let them have a certain see-through power, more than the accidental one, maybe based on the sensor upgrade level.
Also, what do you think about distinguishing between lava and water?
the sensorview program doesn't even run with the sonic sensor in the slot it just goes back to the command line, and the program crashes if we try and use it in a turtle. (we have tried deleting the OCS/lua folder but no luck)
that explanation works.
the sensors are being hidden to keep it from being destroyed by mobs, I'm helping my brother make a "danger room" and having exposed sensors would be a bad idea....especially with creepers and Ogres (Mo'Creatures. Thank goodness for construction foam from IC2)
personally I think it should be able to penetrate a few blocks if the sensor is directly against blocks in that direction, and the penetration range should be dependent on the level of the card
distinguishing what type of liquid would be nice, but not needed. though if you set it up right, you could distinguish any type of liquid

#714 tabs

  • Members
  • 21 posts

Posted 24 February 2013 - 07:22 AM

Is there any way of getting information from a sensor without the mod creating a new tile object each time? This is apparently causing a fair bit of overhead (noticably not smooth when moving around the world). I could be wrong, and also perhaps my programming is at fault.

Every time I call sensor.getTargetDetails(k) using the BC sensor it appears a new object is created (according to the console from the FTB launcher). Does OpenCCSensors handle the destruction of these objects? Does the data get passed to CC and the object immediately destroyed?

I suppose I have two concerns here. One is that I'm not causing too many garbage collections, the other that I need better performance out of my app.

Would there be a way of reusing the tile object to get more recent data, rather than creating a new one? Not really sure what limitations you're working under writing mods like this. There seems to be so many layers of abstraction.

#715 CoolisTheName007

  • Members
  • 304 posts

Posted 24 February 2013 - 09:39 AM

View PostKye_Duo, on 24 February 2013 - 02:53 AM, said:

snip
So it works outside sensorview?

View Posttabs, on 24 February 2013 - 07:22 AM, said:

snip
The fact that something is being printed continually to the console may be the problem? Perhaps someone has forgot to delete a OCSLog call.

#716 Kye_Duo

  • Members
  • 70 posts

Posted 24 February 2013 - 10:23 AM

View PostCoolisTheName007, on 24 February 2013 - 09:39 AM, said:

So it works outside sensorview?
IDK, haven't tried it outside sensor view yet (in the middle of moving servers...original is way underpowerd for MC with all our mods)
tested and it doesn't seem to work...keeps returning a number that increases for every sensor subfunction we use.

#717 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 24 February 2013 - 01:34 PM

That's the event ID to listen for. Actual data is returned in a ocs_response event. The sensor API handles this for you. Load it from ocs/apis/sensor and use either sensor.wrap or sensor.call, which are equivalent in usage to their peripheral API namesakes.

#718 Kye_Duo

  • Members
  • 70 posts

Posted 24 February 2013 - 04:00 PM

View PostLyqyd, on 24 February 2013 - 01:34 PM, said:

That's the event ID to listen for. Actual data is returned in a ocs_response event. The sensor API handles this for you. Load it from ocs/apis/sensor and use either sensor.wrap or sensor.call, which are equivalent in usage to their peripheral API namesakes.
hmmm...can't even get that to work..at least with the sonic sensor. getTargets() returns nothing...won't print the results. no data, not even nil. no error either...but the program works with the other sensor cards...

#719 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 24 February 2013 - 05:44 PM

Please try running this code:

if not os.loadAPI("ocs/apis/sensor") then print("Cannot load API!") return end
local sens
for _, side in pairs(rs.getSides()) do
  if peripheral.isPresent(side) and peripheral.getType(side) == "sensor" then
    print("Sensor found on "..side.." side.")
    sens = sensor.wrap(side)
    break
  end
end
if not sens then print("Could not detect sensor!") return end
print("Sensor type is: "..sens.getSensorName())
local targets = sens.getTargets()
local targetNames = {}
for k, v in pairs(targets) do
  table.insert(targetNames, k)
end
print("Found "..#targetNames.." targets.")
print("Printing targets momentarily.")
sleep(2)
textutils.pagedTabulate(targetNames)

I'm curious to see what it outputs with your sonic sensor, and with the same setup with the card swapped out for a player detector card.

#720 TheGeek

  • Members
  • 60 posts

Posted 25 February 2013 - 04:09 AM

View PostLyqyd, on 24 February 2013 - 05:44 PM, said:

Please try running this code:

if not os.loadAPI("ocs/apis/sensor") then print("Cannot load API!") return end
local sens
for _, side in pairs(rs.getSides()) do
  if peripheral.isPresent(side) and peripheral.getType(side) == "sensor" then
	print("Sensor found on "..side.." side.")
	sens = sensor.wrap(side)
	break
  end
end
if not sens then print("Could not detect sensor!") return end
print("Sensor type is: "..sens.getSensorName())
local targets = sens.getTargets()
local targetNames = {}
for k, v in pairs(targets) do
  table.insert(targetNames, k)
end
print("Found "..#targetNames.." targets.")
print("Printing targets momentarily.")
sleep(2)
textutils.pagedTabulate(targetNames)

I'm curious to see what it outputs with your sonic sensor, and with the same setup with the card swapped out for a player detector card.

Was able to run your example code with the following output:

Sensor found on top side.
Sensor type is: openccsensors.item.sonicsensor

And then nothing. No error generated, just ends. My guess is that it silently errors at the line "local targets = sens.getTargets()", or that the table targets is empty.

And the output of the proximity sensor card:
Sensor found on top side.
Sensor type is: openccsensors.item.proximitysensor
Found 1 targets.
Printing targets momentarily.
TheGeek007

What next?

Edited by TheGeek, 25 February 2013 - 04:22 AM.






6 user(s) are reading this topic

0 members, 6 guests, 0 anonymous users