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

Getting A nil error

Started by jewelshisen, 23 April 2014 - 06:28 PM
jewelshisen #1
Posted 23 April 2014 - 08:28 PM

rednet.open("top")
local Status = {}
function Lockdown()
  rednet.send(25, "Lock", "Security")
  rednet.send(11, "Lock", "Security")
  rednet.send(13, "Lock", "Security")
  Status.Front = "Locked"
  Status.Back = "Locked"
  Status.Ninja = "Locked"
end
function LockToggle()
  if Status[Command] == "Locked" then
    rednet.send(ComControl[Command], "Open", "Security")
    Status[Command] = "Unlocked"
    rednet.send(ID, Status[Command])
  elseif Status[Command] == "Unlocked" then
    rednet.send(ComControl[Command], "Lock", "Security")
    Status[Command] = "Locked"
    rednet.send(ID, Status[Command])
  end
end
local Access = {
  Jewel = "Alpha01",
  Admin = "AdminCode"
}
local AccessLevel = {
  Jewel = "1",
  Admin = "1"
}
local ComControl = {
  Front = "13",
  Back = "11",
  Ninja = "25"
}
local Status = {}
Lockdown()
while true do
ID, User, Pass = rednet.receive()
if Access[User] == Pass then
  rednet.send(ID, "Access Level "..AccessLevel[User].." granted.", 0)
  sleep(0.1)
  rednet.send(ID, "Please Enter Command:")
  ID, Command = rednet.receive()
  if Command == "Lockdown" then
    Lockdown()
    rednet.send(ID, "Facility on Level 1 Lockdown.")
    while true do
	  ID, User, Pass = rednet.receive()
	  if Access[User] == Pass then
	    rednet.send(ID, "Lockdown Lifted.")
	    break
	  else
	    rednet.send(ID, "Error")
	  end
    end
  elseif Command == "Front" or Command == "Back" or Command == "Ninja" then
    LockToggle()
  else
    rednet.send(ID, "INVALID COMMAND")
  end
else
  rednet.send(ID, "Invalid User/Pass")
end
end

The error keeps coming up at line 16 every time I try to have it run that function.
MKlegoman357 #2
Posted 23 April 2014 - 08:31 PM
Could you provide us the full error?
jewelshisen #3
Posted 23 April 2014 - 08:35 PM
Could you provide us the full error?

Well I corrected the nil error and now I am gettng a rednet error saying it keeps expecting a number but not telling me where it is happening.

FOUND IT! The original error seems to have been due to me setting the function before I defined the table. The second error was due to ComControl storing the numbers as strings rather than the number that rednet needed.