Jump to content

  • Curse Sites
Become a Premium Member! Help
Latest News Article

ComputerCraft - attempted to call nil?


  • Please log in to reply
8 replies to this topic

#1

Mort96
    Mort96

    Gold Miner

  • Members
  • 456 posts
  • Location: at the minecraft ORE redstone server
  • Minecraft: mort96

Posted 06 January 2012 - 09:13 PM

Hello everyone.
I just made this small script in computercraft:
running = true
Door = "nil"

while running == true do

Door = read()

if Door == "exit()" then
  running = false
elseif Door == "1" then
  serialData (1, 0, 0, 0)
end

function serialData (A, B, C, D)
  redstone.setOutput ("bottom", true)

  if A == 1 then
	redstone.setOutput ("bottom", true)
  else
	redstone.setOutput ("bottom", false)
  end
  sleep (0.2)

  if B == 1 then
	redstone.setOutput ("bottom", true)
  else
	redstone.setOutput ("bottom", false)
  end
  sleep (0.2) 

  if C == 1 then
	redstone.setOutput ("bottom", true)
  else
	redstone.setOutput ("bottom", false)
  end
  sleep (0.2)

  if D == 1 then
	redstone.setOutput ("bottom", true)
  else
	redstone.setOutput ("bottom", false)
  end
  sleep (0.2)

end

end

Every time I run it, I get the 'attempted to call nil' message after pressing '1' and therefore written '1' to Door.
Does anyone know what I've done wrong?

Register or log in to remove.

#2

elrond1369
  • Minecraft: elrond1369

Posted 06 January 2012 - 10:55 PM

View PostMort96, on 06 January 2012 - 09:13 PM, said:

Hello everyone.
I just made this small script in computercraft:
running = true
Door = "nil"

while running == true do

Door = read()

if Door == "exit()" then
  running = false
elseif Door == "1" then
  serialData (1, 0, 0, 0)
end

function serialData (A, B, C, D)
  redstone.setOutput ("bottom", true)

  if A == 1 then
	redstone.setOutput ("bottom", true)
  else
	redstone.setOutput ("bottom", false)
  end
  sleep (0.2)

  if B == 1 then
	redstone.setOutput ("bottom", true)
  else
	redstone.setOutput ("bottom", false)
  end
  sleep (0.2) 

  if C == 1 then
	redstone.setOutput ("bottom", true)
  else
	redstone.setOutput ("bottom", false)
  end
  sleep (0.2)

  if D == 1 then
	redstone.setOutput ("bottom", true)
  else
	redstone.setOutput ("bottom", false)
  end
  sleep (0.2)

end

end

Every time I run it, I get the 'attempted to call nil' message after pressing '1' and therefore written '1' to Door.
Does anyone know what I've done wrong?
If you put anything before if you will get nil so you can't use elseif because it isn't running a argument it's trying to find the command elseif. Also you don't want to start with door = nil without it door won't be a variable until you type somthing in.
I recommend this
File name: startup
write("Password:")

password = read()
if password == "password" then
shell.run("unlock")
else
write("Incorrect Password!") sleep(2) os.shutdown()
end
File name: unlock
shell.run("clear")
redstone.setOutput("bottom", true)
print(" [1]  exit")

option = read()

if option == "1" then
os.shutdown()
else write("Invalid option try again...") sleep(2) shell.run("unlock")
end
If you want somthing more you can download my Safety Deposit Box program and edit it. It's on the Computer Craft library topic on the 4th page

#3

Poesidon2012

Posted 18 January 2012 - 12:42 AM

I have that problem too.

#4

trans08
    trans08

    Tree Puncher

  • Members
  • 12 posts

Posted 22 July 2012 - 11:43 AM

View Postelrond1369, on 06 January 2012 - 10:55 PM, said:

If you put anything before if you will get nil so you can't use elseif because it isn't running a argument it's trying to find the command elseif. Also you don't want to start with door = nil without it door won't be a variable until you type somthing in.
I recommend this
File name: startup
write("Password:")

password = read()
if password == "password" then
shell.run("unlock")
else
write("Incorrect Password!") sleep(2) os.shutdown()
end
File name: unlock
shell.run("clear")
redstone.setOutput("bottom", true)
print(" [1] exit")

option = read()

if option == "1" then
os.shutdown()
else write("Invalid option try again...") sleep(2) shell.run("unlock")
end
If you want somthing more you can download my Safety Deposit Box program and edit it. It's on the Computer Craft library topic on the 4th page
I get a error saying "unlock :2: attempt to call nil".

#5

Gringomotel

Posted 12 January 2013 - 04:35 PM

hi guys, I'm trying to make a regular password protected door with a redstone wire behind the computer and under a double reinforced stone door. this is how my code looks and it's probably sloppy but I'm very bad at cc. and I'm using it as a startup program.

however I get up startup:3: attempt to call nil, doesn't that mean that my third line dont exist ?

os.pullEvent = os.pullEventRaw
term.clear()
term.setcursorpos(1,1)
print ("Please enter password: ")
input = read("*")
if input == "TIC" then
print ("Welcome")

rs.setoutput("back", true)
sleep(5)
rs.setoutpu("back", false)

else
print("ACCESS DENIED")
sleep(3)

os.shutdown()
end

#6

Gringomotel

Posted 12 January 2013 - 04:35 PM

hi guys, I'm trying to make a regular password protected door with a redstone wire behind the computer and under a double reinforced stone door. this is how my code looks and it's probably sloppy but I'm very bad at cc. and I'm using it as a startup program.

however I get up startup:3: attempt to call nil, doesn't that mean that my third line dont exist ?

os.pullEvent = os.pullEventRaw
term.clear()
term.setcursorpos(1,1)
print ("Please enter password: ")
input = read("*")
if input == "TIC" then
print ("Welcome")

rs.setoutput("back", true)
sleep(5)
rs.setoutpu("back", false)

else
print("ACCESS DENIED")
sleep(3)

os.shutdown()
end

#7

Gringomotel

Posted 12 January 2013 - 04:37 PM

hi guys, I'm trying to make a regular password protected door with a redstone wire behind the computer and under a double reinforced stone door. this is how my code looks and it's probably sloppy but I'm very bad at cc. and I'm using it as a startup program.

however I get up startup:3: attempt to call nil, doesn't that mean that my third line dont exist ?

os.pullEvent = os.pullEventRaw
term.clear()
term.setcursorpos(1,1)
print ("Please enter password: ")
input = read("*")
if input == "TIC" then
print ("Welcome")

rs.setoutput("back", true)
sleep(5)
rs.setoutpu("back", false)

else
print("ACCESS DENIED")
sleep(3)

os.shutdown()
end

#8

TrinityHax

Posted 29 March 2013 - 11:30 AM

View PostGringomotel, on 12 January 2013 - 04:37 PM, said:

hi guys, I'm trying to make a regular password protected door with a redstone wire behind the computer and under a double reinforced stone door. this is how my code looks and it's probably sloppy but I'm very bad at cc. and I'm using it as a startup program.

however I get up startup:3: attempt to call nil, doesn't that mean that my third line dont exist ?

os.pullEvent = os.pullEventRaw
term.clear()
term.setcursorpos(1,1)
print ("Please enter password: ")
input = read("*")
if input == "TIC" then
print ("Welcome")

rs.setoutput("back", true)
sleep(5)
rs.setoutpu("back", false)

else
print("ACCESS DENIED")
sleep(3)

os.shutdown()
end

line 3: term.setcursorpos(1,1)
line 9: rs.setoutput("back", true)
line 11: rs.setoutpu("back", false)

should be:

term.setCursorPos(1,1)
rs.setOutput("back", true)
rs.setOutpu("back", false)

because its case sensitive

#9

MessOfGaming101

Posted 17 May 2013 - 04:52 PM

View PostGringomotel, on 12 January 2013 - 04:35 PM, said:

hi guys, I'm trying to make a regular password protected door with a redstone wire behind the computer and under a double reinforced stone door. this is how my code looks and it's probably sloppy but I'm very bad at cc. and I'm using it as a startup program.

however I get up startup:3: attempt to call nil, doesn't that mean that my third line dont exist ?

os.pullEvent = os.pullEventRaw
term.clear()
term.setcursorpos(1,1)
print ("Please enter password: ")
input = read("*")
if input == "TIC" then
print ("Welcome")

rs.setoutput("back", true)
sleep(5)
rs.setoutpu("back", false)

else
print("ACCESS DENIED")
sleep(3)

os.shutdown()
end
first u forgot a t on the rs.setoutput("back", false)
also you need to capitalize all the O's in the words Output
you also need to capitalize the C in cursor

if you need more help just write me!