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

[Lua] [Error]

Started by tentacleTherapist, 20 October 2012 - 05:12 AM
tentacleTherapist #1
Posted 20 October 2012 - 07:12 AM
Hey guys! I'm totally new to ComputerCraft, but I need it to work a certain function in my adventure map I'm making.

I'll tell you the scenario first so you can better understand it, then post my code, and finally the error I get.

So basically my map makes you go and find a floppy disk called Sburb Beta. Pretty simple. You return to your room where you have a computer asking for you to insert Sburb Beta into your disk drive. You insert it, and the computer sends a redstone signal out the back to a teleporter underneath you that teleports you to the next part of the map.

Now for the code:

term.clear()
term.setCursorPos(1, 1)
print("Insert Sburb Beta.")
while true do
event = os.pullEvent("disk")
sFile = "disk/pass"
hRead = assert(fs.open(sFile, "r"))
sPass = hRead.readLine()
hRead.close()
if sPass == "Enter" then
print("Welcome to Sburb Beta.")
redstone.setOuput("back", true)
sleep(3)
os.reboot()
else
print("Please try again!")
sleep(3)
os.reboot()
end
end

Almost all credit for the code goes to Arkandos!

And last but not least my error message. The program seems to run fine as I set it to run on startup, and it displays the first message and everything, but when I insert the disk I get this message:

Welcome to Sburb Beta.
startup:12: attempt to call nil

From what I can tell, it does not send a signal, or do anything past printing the message.

Any help would be greatly appreciated! It is pretty hard for me to move on without this component of the map!
Kingdaro #2
Posted 20 October 2012 - 07:23 AM
You misspelled "setOutput" as "setOuput".

Also, you can just write "redstone" as "rs", unless you prefer to write "redstone".
ChunLing #3
Posted 20 October 2012 - 08:45 AM
Heheh, the "Ouput" was causing your problem.
billysback #4
Posted 20 October 2012 - 08:49 AM

term.clear()
term.setCursorPos(1, 1)
print("Insert Sburb Beta.")
while true do
  event = os.pullEvent("disk")

  sFile = "disk/pass"
  hRead = assert(fs.open(sFile, "r"))
  sPass = hRead.readLine()
  hRead.close()

  if sPass == "Enter" then
	print("Welcome to Sburb Beta.")
	redstone.setOuput("back", true)
	sleep(3)
	os.reboot()
  else
	print("Please try again!")
	sleep(3)
	os.reboot()
  end
end
Please tab, it makes code so much easier to read and debug, it isn't something you should be adding in, it should be something you do whilst coding!
ChunLing #5
Posted 20 October 2012 - 09:03 AM
True enough. If you haven't properly tabbed your code, then that indicates that you haven't really tried to fix it yourself before asking for help. Then again, I'm super terrible about tabbing. Like, not even normal terrible of just not tabbing at all, but where my tabbing actually probably makes it harder for others to follow my code.
tentacleTherapist #6
Posted 20 October 2012 - 04:34 PM
Thanks for the help! I didn't even see that mistake. And as I said I'm completely new to this I had no idea what tabbing even meant until you showed me! Thanks everyone it seems to work fine now!