Jump to content




[MC 1.7.10 | CC 1.65] OpenCCSensors

lua

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

#941 Mosty

  • Members
  • 3 posts

Posted 18 May 2013 - 05:26 AM

First of all, thank you for a great plugin!

I'm trying to figure the sonic sensor card out. However i have some trouble to get the result that I would expect.
To try to explain the problems i have done some test, which are shown here:
Spoiler

Test 1:
I am wondering why the 3 blocks in front(+X) of the turtle are reported as unknown. Seems like a bug, since that a block will only report as unknown if there is no block at +X.

Test 2:
Everything looks OK. This implies that it is correct that the sensor shouldn't be able to scan blocks where the vector from the turtle to the block is blocked by another block. However if I do the same test with the blocks either one level above or under the turtle(i.e. y=1 or y=-1) the result is the same. E.g. block at (0,1,2) cannot be detected, when there is a block at (0,1,1), even though there is no block at (0,0,1) or (0,0,2). In this case there is no block blocking the vector between the turtle and the scanned block.

Test 3:
Some blocks are reported as unknown. I guess the reason for this is the same as in "Test 1". Another thing is the corners. The -X corners cannot be scanned while the +X corners can.

Test 4:
The liquid seems to be misplaced 1 block out of the negative x axis.

In general:
I like the idea that you cannot scan blocks where the vector between the turtle and the block is blocked by another block, however this doesn't seem to work correctly. Another problem with this is that, the only way i can detect if a scanned block is air or if it could not be scanned, is to figure out for my self if there is another blocking the path between the turtle and the scanned block. This could be solved by returning a block of "Type" AIR, when the block could be scanned and only contains air.
Another thing is the coordinates returned together with the block type. They are always -1 X off, compared to the coordinates given in the scan request. What is the reason for this?

Edit:
After looking at the source code for the sonicSensor.java, i see that i looks like that you ment to be able to query any block within the sensor range. So is it a bug that you cannot detect a block at (0,0,2) if there is a block at (0,0,1)?
Another thing i noticed, is that getTargets() is implemented in the java code. This does not work when called from lua. Thought this was as it was ment to be, but now i think it is a bug?

#942 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 18 May 2013 - 11:26 AM

Oh thanks for the detailed investigation!

The sonic sensor is one of the few cards I didnt create, so I'll have to familiarize myself with the code a bit more.

I'll take a look at it when I get home tonight and probably write a testing script thatll make it easy to see whats working and whats not.

If its bugged I'll put out a new release tomorrow.

#943 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 18 May 2013 - 02:01 PM

View PostPixelToast, on 17 May 2013 - 12:55 PM, said:


These are nice. I think I like what we currently have better. It isn't my decision, though. :)

#944 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 18 May 2013 - 04:03 PM

RELEASE

Ok, I've had to change the behaviour of the sonic sensor due to bugs with the raycasting. It'll now return all blocks within the range of the sensor.

However, to compensate a bit, I've changed the range to a circular radius, and I've also reduced the range quite a bit.

Video

Here's a video showing it off:



Download

https://dl.dropboxus...sors-0.1.5i.jar

Example

Here's the example script I used in the video:

-- sensor on the floor
-- computer above the sensor
-- monitor above the computer
-- monitor can be any size

-- make sure the whole setup is FACING north.
-- the monitor must be facing north!

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

local sonic = sensor.wrap("bottom")

local monitor = peripheral.wrap("top")

local centerY = 0
local centerZ = 0
local width = 0
local height = 0


-- draw a block on the screen
function drawBlock(block)

  local c = colors.white

  if block.Type == "SOLID" then
	c = colors.yellow  
  elseif block.Type == "LIQUID" then
	c = colors.lightBlue  
  end

  monitor.setBackgroundColor(c)
  monitor.setCursorPos(centerX - block.Position.X, centerY - block.Position.Z)
  monitor.write(" ")

end


-- forever...
while true do

  -- get the monitor width and height (in case it changes, we'll do this every loop)  
  width, height = monitor.getSize()

  -- find the center point
  centerX = width / 2;
  centerY = height / 2;

  -- get all the targets available
  local targets = sonic.getTargets()

  -- clear the monitor (to black)
  monitor.setBackgroundColor(colors.black)
  monitor.clear()

  -- draw the sensor block
  drawBlock({
	Position =  {
	  X = 0,
	  Z = 0
	},
	Type = "SENSOR"
  });

  -- loop through all the data from the sensor
  for key, data in pairs(targets) do

	-- if the Y position is the same as the sensor
	if data.Position.Y == 0 then

	  -- draw the block
	  drawBlock(data)

	end

  end

  -- wait a second before doing it again
  sleep(1)

end


#945 Mosty

  • Members
  • 3 posts

Posted 18 May 2013 - 04:30 PM

Extremely Awesome! Thank you.

I didn't expect you to come up with a fix that soon, and that good.

Now my turtles will be more powerful than ever :-D

#946 Mosty

  • Members
  • 3 posts

Posted 19 May 2013 - 02:59 AM

I cannot create the sign sensor card.

It looks like block id 63 is used instead of block id 323 for the sign in the recipe.
Posted Image

#947 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 19 May 2013 - 04:57 AM

Damn I must've recently introduced that. Ill add a fix to the next release, but I think ill wait a little while before putting another release out. Too many little releases and not enough new features.

Thanks for spotting it

#948 Xalithar Daskel

  • Members
  • 3 posts

Posted 21 May 2013 - 03:46 PM

When I look at this mod, I kind of ponder what kind of potential that this CC Addon has in mind of what it can be used for. In my opinion, this would be a brilliant way for Adventure Map Creators to use this type of Addon to make some interesting event triggers. Sure, this can already be done if one didn't use this addon, but with it, I would say that the functionality would be made a whole lot more compact.

#949 goalie1248

  • New Members
  • 2 posts

Posted 21 May 2013 - 07:04 PM

Is there a way to use the Tank sensor card to sense what kind of liquid is in the tank? Like lava or water?
I was looking at this vid:

Basically wondering how it was able to detect the change so it was able to change from blue for water, to red for lava?

EDIT: Edited for clarity and grammar

#950 ThatGamingGnome

  • Members
  • 4 posts
  • Locationhttp://www.youtube.com/user/ThatGamingGnome

Posted 22 May 2013 - 07:46 PM

I'm running into an issue with the proximity sensor cards. I have a sensor detecting a specific player that sends a signal to another computer. My problem is with line 13 (playerName = targetsDetail.Username). This code works roughly 80% of the time, but sometimes I get (attempt to index ? (a nil value)) at line 13. Anyone have any thoughts?

os.unloadAPI("ocs/apis/sensor")
os.loadAPI("ocs/apis/sensor")
local prox = sensor.wrap("top")
local modem = peripheral.wrap("right")
local playerName = ""
local player = "StarmanTristam"
function nameCheck()
local targets = prox.getTargets()
--Read data from sensor
   for k, v in pairs(targets) do
      if ((v.Name) == "Player") then
         targetsDetail = prox.getTargetDetails(k)
         playerName = targetsDetail.Username
      end
   end
   if (playerName == player) then
      modem.transmit(87,54,"fuzzy_pickles")
   else
      modem.transmit(87,54,"not_player")
   end
end
while true do
   nameCheck()
   sleep(1)
end


#951 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 22 May 2013 - 08:25 PM

Occasionally, a target will be in range when the list of targets is fetched, but move out of range before you get the details on them. In that case, the targetsDetail table would be nil.

#952 ThatGamingGnome

  • Members
  • 4 posts
  • Locationhttp://www.youtube.com/user/ThatGamingGnome

Posted 22 May 2013 - 09:10 PM

View PostLyqyd, on 22 May 2013 - 08:25 PM, said:

Occasionally, a target will be in range when the list of targets is fetched, but move out of range before you get the details on them. In that case, the targetsDetail table would be nil.

Would there be any clever way around this?

I think I actually found a way around this by just checking before I assign any variables to see if anything is nil.

Edited by ThatGamingGnome, 22 May 2013 - 10:46 PM.


#953 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 23 May 2013 - 07:29 AM


os.loadAPI("ocs/apis/sensor")
local prox = sensor.wrap("top")
local modem = peripheral.wrap("right")
local playerName = ""
local player = "StarmanTristam"
function nameCheck()
local targets = prox.getTargets()
--Read data from sensor
   for k, v in pairs(targets) do
      if ((v.Name) == "Player") then
         targetsDetail = prox.getTargetDetails(k)
         if targetDetails ~= nil then
           playerName = targetsDetail.Username
         end
      end
   end
   if (playerName == player) then
      modem.transmit(87,54,"fuzzy_pickles")
   else
      modem.transmit(87,54,"not_player")
   end
end
while true do
   nameCheck()
   sleep(1)
end


#954 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 23 May 2013 - 05:45 PM

A new release. OpenCCSensors 1.5.2.0

Yes, 1.5.2.0!

The previous weird version numbering was driving me mad because it made no sense at all. Version numbers will now reflect the newest version of minecraft it supports, along with an incremental revision number on the end. (so next release will be 1.5.2.1)

Changelog:

Adding turtles back into the creative tab as they're no longer added to the CC creative tab.
Fixed the sign sensor recipe

https://dl.dropboxus...ors-1.5.2.0.jar

#955 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 25 May 2013 - 07:13 AM

I'm sure most other mods suffer from this - but I've noticed OpenCCSensors files pop up on dodgy russian sites, with a larger file size than the actual release.

Please always make sure you download any mod from a source that you trust, so either an official thread, a well known launcher, or if you know how just compile it yourself.

cheers!

#956 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 26 May 2013 - 03:14 PM

Neat little trick you can do with OpenCCSensors proximity blocks and TE illuminators..



#957 energist

  • New Members
  • 1 posts

Posted 26 May 2013 - 07:18 PM

This mod looks interesting. I'm unfortunately not able to get it to work. I keep getting a "no such program" return when trying just about any command. It has no directory nor program available. I have the sensor set up adjacent to the computer with the proximity sensor installed. I would greatly appreciate some help.

Edit: I'm running a server on Beastnode, and using the latest version of tekkit.

#958 frostymm

  • Members
  • 5 posts

Posted 27 May 2013 - 12:55 AM

Hey just a small request from a fellow programmer, do you think you could post some more example code on the wiki? Or tell me where I can find at least what you have in the video's? This mod is pretty awesome but I'm having trouble getting started and I learn best from pulling from examples ^^' It took me half the day searching around to figure out how enough stuff worked to write my own code for searching for specific players and opening some doors while having the ability to also accept a password input alternatively (lua is... different). And now I'm stuck on figuring out how to make the sensor turtle work since it doesn't have any "side" for the sensor to wrap on. I'd just like to see some work that's already been done so I can pull from it what I need, I'd greatly appreciate the help!

#959 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 27 May 2013 - 02:04 AM

More example code would be valuable; it's true. If you can provide some simple suggestions for example code, that would be helpful. I can provide high-quality code samples, I'm just not always sure what would be most helpful.

Also, in case you didn't know about it, the ocs/programs/sensorview program can be invaluable to help determine which values you are wanting to look up. Instructions for its use are included in the first post. :)

#960 TolkienLore

  • Members
  • 3 posts

Posted 27 May 2013 - 03:21 AM

Okay, I am probably running into a stupid mistake on my part, but I just can't get this working.
Just a test script, bugs are commented in, but generally, I can see the functions; however, calling them returns nil or not the intended type.

local _DEBUG = true

os.unloadAPI("ocs/apis/sensor")
os.unloadAPI("rom/apis/invmanager")
os.loadAPI("ocs/apis/sensor")
os.loadAPI("rom/apis/invmanager")

local sensor,sorter

if _DEBUG then
  local methods
end

--Test for Inventory Manager, suffering same issue as openCCsensor.
if _DEBUG then
  print(peripheral.getType("left"))
  methods = peripheral.getMethods("left")
  for k,v in pairs(methods) do
	print(k..": "..v.."("..type(v)..")")
  end
  --Test to see if it is returning a table, returns nothing
  --print(type(peripheral.call("left","read","south",1)))
end
if peripheral.getType("left") == "InventoryManager" then
  print("Found Inventory Manager. Wrapping...")
  sorter = peripheral.wrap("left")
end

--Test for sensor.
if _DEBUG then
  print(peripheral.getType("top"))
  methods = peripheral.getMethods("top")
  for k,v in pairs(methods) do
	print(k..": "..v.."("..type(v)..")")
  end
end
if peripheral.getType("top") == "sensor"  then
  print("Found Sensor. Wrapping...")
  sensor = peripheral.wrap("top")
end

--sensor.getTargets() is returning a number instead of a table.
local targets = sensor.getTargets()
for k,v in targets do
  for j,l in pairs(sensor.getTargetDetails(v)) do
	print(l)
  end
end


I have been going at it for almost a full day and am at a loss as to what is going on.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users