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

Chest Peripheral Error

Started by David_Mozi, 02 January 2016 - 11:58 AM
David_Mozi #1
Posted 02 January 2016 - 12:58 PM
Hey I've got the Idea to make a password protected door with items, but everytime when I start the program an error appears: .temp:6: attempt to index ? (a nil value)

Here's the Code:


chest = peripheral.wrap("right")
password = chest.getStackInSlot(1)
print("Bitte Item einlegen")if password.raw_name == "tile.extrautils:chandelier" then
  print("Passwort richtig")
  rs.setOutput("top",true)
  sleep(7)
  rs.setOutput("top",false)
  else
	print("Passwort falsch")
end
os.reboot()

Sry for my bad english :D/> I'm from Germany
LBPHacker #2
Posted 02 January 2016 - 05:11 PM
That raises a bunch of questions, since there's nothing that can result in that error on line 6. Is your program really called ".temp"? Did you get the lines right? Didn't you miss a line break?

If you did miss a line break and the if statement is on a separate line, the only thing I can think of is that you misspelled rs in your program but not here.
HPWebcamAble #3
Posted 02 January 2016 - 06:39 PM
Is your program really called ".temp"?

I doubt it. That's the name of the temporary file the the 'edit' program uses when running code from the editor
David_Mozi #4
Posted 02 January 2016 - 08:10 PM
Is your program really called ".temp"?

I doubt it. That's the name of the temporary file the the 'edit' program uses when running code from the editor


chest = peripheral.wrap("right")
password = chest.getStackInSlot(1)
print("Bitte Item einlegen")
  if password.raw_name == "tile.extrautils:chandelier" then
  print("Passwort richtig")
  rs.setOutput("top",true)
  sleep(7)
  rs.setOutput("top",false)
  else
	    print("Passwort falsch")
end
os.reboot()

Now there is an Error in Line 4
LBPHacker #5
Posted 02 January 2016 - 09:45 PM
Well, that means that password is nil. If the error is the same, that is. I'm guessing it's because your program checks for an item at startup and not when you put your tile.extrautils:chandelier in the chest.
HPWebcamAble #6
Posted 03 January 2016 - 12:12 AM
Like LBP mentioned, password will be nil if there isn't an item in slot one when the code runs.

You need to check that password has a value before trying to access it like a table:

if type( password ) == "table" and password.raw_name == "tile.extrautils:chandelier" then
David_Mozi #7
Posted 03 January 2016 - 12:58 PM
Well, that means that password is nil. If the error is the same, that is. I'm guessing it's because your program checks for an item at startup and not when you put your tile.extrautils:chandelier in the chest.
Like LBP mentioned, password will be nil if there isn't an item in slot one when the code runs.

You need to check that password has a value before trying to access it like a table:

if type( password ) == "table" and password.raw_name == "tile.extrautils:chandelier" then

Thank you Guys :)/> now it works :)/>