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

bios:145: attempt to call nil

Started by Jacster4, 28 October 2014 - 07:49 PM
Jacster4 #1
Posted 28 October 2014 - 08:49 PM
Hey guys I have been having problems with my doorlock code it says
BlockDefender 3.1Loading Program.bios:145: attempt to call nil
> bios :257: attempt to call nil
Goodbye
bios:145: attempt to call nil

Code: os.pullEvent = os.pullEventraw
local password = "derp69"
local doorside = "right"
local opentime = 3
local loadtime = 1
while true do
term.clear()
term.setCursorPos(1,1)
write "BlockDefender 3.1"
write "Loading Program."
sleep (loadtime)
write "Loading Program.."
sleep (loadtime)
write "Loading Program…"
sleep (loadtime)
write "Loading Program."
sleep (loadtime)
write "Password: "
local input = read ("*")
if input == password then
term.clear()
term.setCursorPos (1,1)
write "Logging in."
sleep (loadtime)
write "Logging in.."
sleep (loadtime)
write "Logging in…"
sleep (loadtime)
write "Logging in."
sleep (loadtime)
write "Login Accepted."
rs.setOutput (doorside,true)
sleep (opentime)
rs.setOutput (doorside,false)
os.shutdown()
else
term.clear()
term.setCursor (1,1)
write "Logging in."
sleep (loadtime)
write "Logging in.."
sleep (loadtime)
write "Logging in…"
sleep (loadtime)
write "Logging in."
sleep (loadtime)
write "Login Failed. Try again."
sleep(3)
end
end
Lyqyd #2
Posted 28 October 2014 - 09:03 PM
Lua is case-sensitive. os.pullEventraw and os.pullEventRaw are different things, and only the second one exists in a freshly booted computer.
Jacster4 #3
Posted 28 October 2014 - 09:24 PM
Wow that worked thank you very much! :)/>
Dragon53535 #4
Posted 28 October 2014 - 09:47 PM
To back up Lyqyd's answer, which is right. Your error is happening at the point where you put

sleep(loadtime)
Because sleep is really just this code

function sleep(num)
  local timer = os.startTimer(num)
  while true do
    local event = {os.pullEvent()}
    if event[2] == timer then
	  break
    end
  end
end
If you notice inside it calls os.pullEvent() however since at the top you set it to os.pullEventraw (which doesn't exist/is nil) it's terminating since it can't call a nil value.
The fix is just to have it as

os.pullEvent = os.pullEventRaw
at the top