1 posts
Posted 31 January 2014 - 10:29 PM
shell.run("startup")
door = 'left'
alarm = 'bottom'
password = 'turtle'
password2 = 'FOREVER'
mon = peripheral.wrap("right")
term.clear()
term.setCursorPos(1,1)
print('Password Please')
guess = read('*')
if password == guess then
mon.clear()
mon.setTextScale(1)
mon.setCursorPos
mon.write("Proceed")
rs.setOutput(door,true)
sleep(15)
rs.setOutput(door,false)
if password2 == guess then
mon.clear()
mon.setTextScale(1)
mon.setCursorPos(5,5)
mon.write("Door Open Forever")
rs.setOutput(door,true)
else
rs.setOutput(alarm,true)
mon.clear()
mon.setTextScale(1)
mon.setCursorPos(5,5)
mon.write("Remove your self")
sleep(20)
rs.setOutput(alarm,false)
mon.clear()
end
end
whats wrong here? evertime I run this and put in it comes up with Proceed on the monitors and then after a bit goes to remove yourself and sounds the alarm
8543 posts
Posted 01 February 2014 - 01:00 AM
Moved to Ask a Pro.
23 posts
Posted 01 February 2014 - 01:46 AM
Looks kind of derpy - you only check if guess was password2 if guess is password which doesnt make any sense. Remove end in last line and change
if password2 == guess then
to
elseif password2 == guess then
Edited on 01 February 2014 - 12:47 AM
286 posts
Location
United States
Posted 01 February 2014 - 04:52 AM
Here is your code formatted with [member='Farrk']'s correction. It doesn't look too derpy, just made a mistake on the
if .. elseif .. else .. end construct.
shell.run("startup")
door = 'left'
alarm = 'bottom'
password = 'turtle'
password2 = 'FOREVER'
mon = peripheral.wrap("right")
term.clear()
term.setCursorPos(1,1)
print('Password Please')
guess = read('*')
if password == guess then
mon.clear()
mon.setTextScale(1)
mon.setCursorPos
mon.write("Proceed")
rs.setOutput(door,true)
sleep(15)
rs.setOutput(door,false)
elseif password2 == guess then
mon.clear()
mon.setTextScale(1)
mon.setCursorPos(5,5)
mon.write("Door Open Forever")
rs.setOutput(door,true)
else
rs.setOutput(alarm,true)
mon.clear()
mon.setTextScale(1)
mon.setCursorPos(5,5)
mon.write("Remove your self")
sleep(20)
rs.setOutput(alarm,false)
mon.clear()
end
Are you sure you want to do the
shell.run("startup") at the beginning there?
Everybody starts coding in Lua with something. It is the only way to learn :)/>
Edited on 01 February 2014 - 03:55 AM
1220 posts
Location
Earth orbit
Posted 01 February 2014 - 01:26 PM
Here's the cleaned up code with all the variables localized…
shell.run("startup")
local door = 'left'
local alarm = 'bottom'
local password = 'turtle'
local password2 = 'FOREVER'
local mon = peripheral.wrap("right")
term.clear()
term.setCursorPos(1,1)
print('Password Please')
local guess = read('*')
if password == guess then
mon.clear()
mon.setTextScale(1)
mon.setCursorPos
mon.write("Proceed")
rs.setOutput(door,true)
sleep(15)
rs.setOutput(door,false)
elseif password2 == guess then
mon.clear()
mon.setTextScale(1)
mon.setCursorPos(5,5)
mon.write("Door Open Forever")
rs.setOutput(door,true)
else
rs.setOutput(alarm,true)
mon.clear()
mon.setTextScale(1)
mon.setCursorPos(5,5)
mon.write("Remove your self")
sleep(20)
rs.setOutput(alarm,false)
mon.clear()
end
47 posts
Location
tekkit.craftersland.net:25567
Posted 01 February 2014 - 04:22 PM
Shouldn't that be like
if guess == password1
?
Edited on 01 February 2014 - 03:23 PM
91 posts
Posted 01 February 2014 - 04:41 PM
Shouldn't that be like
if guess == password1
?
No. password is the name of his variable.
47 posts
Location
tekkit.craftersland.net:25567
Posted 02 February 2014 - 02:07 AM
Oh ye. Well, this is what you get for looking things up quickly..
286 posts
Location
United States
Posted 02 February 2014 - 05:03 PM
Here's the cleaned up code with all the variables localized…
Now here's the cleaned up code with all the errors removed:
--shell.run("startup")
local door = 'left'
local alarm = 'bottom'
local password = 'turtle'
local password2 = 'FOREVER'
local mon = peripheral.wrap("right")
term.clear()
term.setCursorPos(1,1)
print('Password Please')
local guess = read('*')
if password == guess then
mon.clear()
mon.setTextScale(1)
mon.setCursorPos(5,5)
mon.write("Proceed")
rs.setOutput(door,true)
sleep(15)
rs.setOutput(door,false)
elseif password2 == guess then
mon.clear()
mon.setTextScale(1)
mon.setCursorPos(5,5)
mon.write("Door Open Forever")
rs.setOutput(door,true)
else
rs.setOutput(alarm,true)
mon.clear()
mon.setTextScale(1)
mon.setCursorPos(5,5)
mon.write("Remove your self")
sleep(20)
rs.setOutput(alarm,false)
mon.clear()
end
In the
if password == guess block, setCursorPos did not have a cursor position argument specified. I supplied one.
It seems to work fine now. I commented out the first line, because it is of no use in my testing.
Edited on 02 February 2014 - 04:05 PM