Jump to content




edit tes


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

#1 IndustrialLemon

  • Members
  • 61 posts

Posted 15 March 2014 - 04:32 PM

So heres the deal. I ripped this code straight from the wiki page on Open CC Sensors, so I could start learning how to use it for player tracking, and it gives me the the error message "test :10: attempt to index ? (a nil value)".
I have no idea what to do!?
Can anyone help me?

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

-- the location of the redstone lamp relative to the sensor
local offset = {
  X = 1,
  Y = 1,
  Z = 0
}

-- how close a player has to be to activate the lamp
local radius = 5
-- find the distance from the player position to the offset
function distance(pos)
  local xd = pos.X - offset.X
  local yd = pos.Y - offset.Y
  local zd = pos.Z - offset.Z
  return math.sqrt(xd*xd + yd*yd + zd*zd)
end

local proximity = sensor.wrap("left")
while true do
  local signal = false
  local targets = proximity.getTargets()
  for k, v in pairs(targets) do
		if distance(v.Position) < radius then
		  signal = true  
		end
  end
  rs.setOutput("top", signal)
end


#2 CometWolf

  • Members
  • 1,283 posts

Posted 15 March 2014 - 04:35 PM

Line 10 is
-- how close a player has to be to activate the lamp
Which is a comment, so this is obviously not your whole code.

#3 IndustrialLemon

  • Members
  • 61 posts

Posted 15 March 2014 - 04:48 PM

Oh sorry. Well I took out the comments when I ran it. Line ten is really
local xd = pos.X - offset.X


#4 CometWolf

  • Members
  • 1,283 posts

Posted 15 March 2014 - 05:05 PM

The only line that calls the distance function is this
			    if distance(v.Position) < radius then
Meaning that v.Position is nil, thus causing the error.
v is a value in the table targets
  for k, v in pairs(targets) do
and finally targets is the result of
  local targets = proximity.getTargets()
Meaning that your sensor isn't detecting any targets. Does it have a card installed?

#5 IndustrialLemon

  • Members
  • 61 posts

Posted 15 March 2014 - 07:39 PM

It does. I actually am using a turtle. The card is in the 16th slot so unless I'm mistaken that's the slot you keep the sensor card.

#6 CometWolf

  • Members
  • 1,283 posts

Posted 15 March 2014 - 08:25 PM

Which card?

#7 IndustrialLemon

  • Members
  • 61 posts

Posted 15 March 2014 - 08:41 PM

Proximity Sensor Card Mk. 4

#8 CometWolf

  • Members
  • 1,283 posts

Posted 15 March 2014 - 08:52 PM

See if you can get the included sensorview program to work

#9 IndustrialLemon

  • Members
  • 61 posts

Posted 15 March 2014 - 08:59 PM

If you were meaning the other included program on the wiki page then I ran that and I got no issues,

#10 CometWolf

  • Members
  • 1,283 posts

Posted 15 March 2014 - 09:02 PM

No i meant the included program, the one already installed on your computer in the ocs folder. However, since you got another sensor related program to work at all, and you apparently took out all the comments, im guessing you wrote the program in by hand? If so, please upload it to pastebin, or take a closer look at it. Chances are you did something wrong.

#11 ElvishJerricco

  • Members
  • 803 posts

Posted 15 March 2014 - 09:04 PM

View PostCometWolf, on 15 March 2014 - 05:05 PM, said:

Meaning that your sensor isn't detecting any targets.

Nope. If this were true the loop simply wouldn't ever run. The problem is elsewhere. Probably a misuse of the API, meaning it's evolved since the wiki-page was last updated.

#12 IndustrialLemon

  • Members
  • 61 posts

Posted 15 March 2014 - 09:05 PM

Thats what I had figured. if you could maybe find a way to check the coords of a nearby player for me that'd be fantastic.

#13 IndustrialLemon

  • Members
  • 61 posts

Posted 15 March 2014 - 09:29 PM

Oh goodie! Got it working everybody. I completely rewrote the program how it was on the forums but never did find what was wrong with mine. It works now though :)

#14 CometWolf

  • Members
  • 1,283 posts

Posted 15 March 2014 - 09:30 PM

Next time use pastebin to transfer code directly instead of writing it by hand.

View PostElvishJerricco, on 15 March 2014 - 09:04 PM, said:

Probably a misuse of the API, meaning it's evolved since the wiki-page was last updated.
This is incorrect, the API has not changed.

#15 Anavrins

  • Members
  • 775 posts

Posted 16 March 2014 - 02:44 AM

Ehh, "Sensors cards" are suposed to go in the "Sensor" block, which then act as a normal peripheral.

#16 CometWolf

  • Members
  • 1,283 posts

Posted 16 March 2014 - 09:58 AM

Not if the sensor is attached to the turtle, like a a modem or a pickaxe.

#17 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 16 March 2014 - 10:02 PM

In OpenCCSensors the turtle has to place the particular sensor 'card' in slot 16 and mount it as "left" if I remember correctly

#18 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 16 March 2014 - 10:07 PM

The turtle must be a sensor turtle (craft a sensor with a turtle to create) and then just have the card in slot sixteen. No need to "mount" anything. :)





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users