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

Simple, noobish keycard problem

Started by RaTheBadger, 10 July 2012 - 09:30 PM
RaTheBadger #1
Posted 10 July 2012 - 11:30 PM
Hey, so, I have a problem with my simple keycard program. I've tried many things but can't figure out what I'm missing on line 3. Here's my code.

print("Enter Room Key.")
if (disk.isPresent(driveSide) ) then
check.label(driveSide,"bottom")
  if (label == "roomkey4d5") then
   redstone.setOutput("left",true)
   print("Welcome Home.")
  else
   print("Invalid Room Key.")
   end
else
print("Room Key Not Detected.")
end
Line 3, which is "check.label(driveSide,"bottom") is almost undoubtedly code that I have written wrongly (This is my first LUA test). What it's supposed to do is check what the name of the key card is, and if it's "roomkey4d5", go to line 5; else, go to line 8. But I'm apparently missing something.
-Thanks, Ra.

EDIT: Problem fixed! Thread may be closed now :)/>/>
xuma202 #2
Posted 10 July 2012 - 11:35 PM
What you need is


label = disk.getLabel(driveSide)

http://computercraft.info/wiki/index.php?title=Disk.getLabel
RaTheBadger #3
Posted 11 July 2012 - 12:39 AM
Thanks Xuma, I'll try that out :)/>/>
EDIT: Tried that, still got the "string expected; got nil" error. I'm not sure, I think I'm still missing something. Nonetheless it was helpful to get the correct code there.

EDIT#2: I've gone from that point and I've managed to get past that problem! Still having some trouble though. I'll keep posting updates.

EDIT#3: Sweetness, I've managed to get it to work. Thread no longer needed B)/>/>
Grim Reaper #4
Posted 11 July 2012 - 12:44 AM
I'm not entirely sure as to if this block of code is the whole program or not. In the case that it is the entire program then I think your problem can be solved by defining the variables: 'driveSide' and 'label'.

You're attempting to pass a nil identifier to a function.

Try this:


driveSide = "back" -- This can be any side. "back" is just used as an example :)/>/>
print("Enter Room Key.")
if (disk.isPresent(driveSide) ) then
check.label(driveSide,"bottom")
  if (label == "roomkey4d5") then
   redstone.setOutput("left",true)
   print("Welcome Home.")
  else
   print("Invalid Room Key.")
   end
else
print("Room Key Not Detected.")
end
RaTheBadger #5
Posted 11 July 2012 - 01:00 AM
Thanks Payment, but it was solved a couple minutes ago B)/>/>
Also; that's pretty much what the working code I have now is :)/>/>