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

Having trouble with a simple program

Started by alfinchkid, 13 March 2012 - 10:00 PM
alfinchkid #1
Posted 13 March 2012 - 11:00 PM
I have a computer that I have wired up to a number of doors. I would like to open these doors with commands from the computer. However, I can't seem to get it working. Here's the code:


print ("Hello")
print ("Where would you like to go today?")
door = io.read()
if door == "Vault 666" then
	 redstone.setOutput("back", false)
	 redstone.setOutput("left", false)
	 redstone.setOutput("right", true)
print ("Opening doorway to Vault 666...")
elseif door == "Vault 101" then
	 redstone.setOutput("back", false)
	 redstone.setOutput("right", false)
	 redstone.setOutput("left", true)
print ("Opening doorway to Vault 101...")
else
print ("Invalid entry.")
end
end

If you could not tell (this is literally the first program I've ever made, I likely got nothing right :mellow:/>/> ), the goal of the program is to ask the user which door to open, and have them enter a name of the door. Then, it will check the name of the door, and send a redstone signal to that door, cutting the other redstone signals. I currently only have two "Vaults" (666, with a Nether Portal, and 101, my bedroom), but will have two more later (unsure of how I'll number them, but they'll use the bottom and back redstone outputs). Vault 666 is to the right of the computer and Vault 101 is to the left. I've checked the wiring using the "redset" command, so I know that the doors will open with the proper redstone outputs. However, when I run the program (The name of the program is called "Open", btw), I get this error message:


> Open
bios:206: [string "Open"]:17: '<eof>' expected

Not sure what this means or what I'm doing wrong. Could someone help me figure out this error message and/or help cleanup my code?
Advert #2
Posted 13 March 2012 - 11:12 PM
You have an extra end.

You should also put this in a loop (so you dont have to restart the program every time):

while true do
 <your code>
end
alfinchkid #3
Posted 13 March 2012 - 11:17 PM
Wow, having that extra end at the end was really it? Huh. Thanks.
Advert #4
Posted 13 March 2012 - 11:37 PM
Wow, having that extra end at the end was really it? Huh. Thanks.

Yeah, you don't need an end to close the script.

You may find this useful: Programming in Lua.

Feel free to make another post if you have any other questions. :mellow:/>/>