This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
AJCA's profile picture

attempt to index ? (a nil value) problem with program

Started by AJCA, 30 July 2016 - 01:54 PM
AJCA #1
Posted 30 July 2016 - 03:54 PM
i have a hand scanner program on a server, it has a radar and a monitor. You right click on the monitor and it will say whether you're allowed in or not, but i need an extra pair of eyes to check my programming. i cant find the problem but i'm hoping one of you could see it. Thank you guys.


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

door = peripheral.wrap("monitor_1")
door.setTextScale(0.5)

radar = sensor.wrap("right")

allow = {}
allow.AlexJCamp = true
allow.pedromac002 = false

avoid = {}
avoid.pedromac002 = true

xMin = -5
xMax = -1
yMin = -6
yMax = -4

term.redirect(door)

handGood = paintutils.loadImage("handGood")
handBad = paintutils.loadImage("handBad")
handNormal = paintutils.loadImage("hand")


–paintutils.drawImage(handNormal,1,1)

local function checkInRange(number, min, max)

return number >= min and number <= max

end

local function checkTargets(targets, compare)

for k,v in pairs(compare) do

if targets[k] then
–print(targets[k].Position.X," ", targets[k].Position.Z
–sleep(8)

if checkInRange(targets[k].Position.X, xMin, xMax) then

if checkInRange(targets[k].Position.Z, yMin, yMax) then
return true
end

end

end
end

return false

end

while true do

timer = os.startTimer(1)

e, k = os.pullEvent()

–term.clear()

–print(table.getn(radar.getTargets()))

if checkTargets(radar.getTargets(),allow) or checkTargets(radar.getTargets(),avoid) then
paintutils.drawImage(handNormal, 1,1)
else
term.clear()
end

if e == "monitor_touch" then
if checkTargets(radar.getTargets(),allow) and not checkTargets(radar.getTargets(), avoid) then
paintutils.drawImage(handGood, 1 1)
rs.setOutput("back", true)
sleep(2)
os.reboot()
else
paintutils.drawImage(handBad, 1,1)
sleep(3)
os.reboot()


end

end

end
RoD #2
Posted 30 July 2016 - 10:33 PM
Allright, you should use the code tags to paste in code :P/>/> second, tell us the full error message. The error message displays the line of the error, which is very useful for debugging.

Edit: noticed you typed

paintutils.drawImage(handGood, 1 1)

instead of


paintutils.drawImage(handGood, 1, 1)

That missing comma might be the error..
Edited on 30 July 2016 - 08:34 PM
KingofGamesYami #3
Posted 30 July 2016 - 11:37 PM
That missing comma might be the error..

It's not, but it's another problem.

I'd guess (without a line number) that the radar peripheral is not being wrapped and therefor is nil when you try to use it.