17 posts
Posted 18 July 2013 - 06:23 AM
So I tried to make one but it doesn't seem to work, any help?
term.clear()
term.setCursorPos(1, 1)
print("Enter password")
pass = read("*")
if pass == "pass" then
print("Welcome")
sleep(2)
term.clear()
term.setCursorPos(1, 1)
else
print("Goodbye")
sleep(2)
shell.run(startup)
end
PS: This is an unfinished version, I want to fix the code before I setup the text shown perfectly.
56 posts
Location
Victoria, AUS
Posted 18 July 2013 - 06:27 AM
So I tried to make one but it doesn't seem to work, any help?
term.clear()
term.setCursorPos(1, 1)
print("Enter password")
pass = read("*")
if pass == "pass" then
print("Welcome")
sleep(2)
term.clear()
term.setCursorPos(1, 1)
else
print("Goodbye")
sleep(2)
shell.run(startup)
end
PS: This is an unfinished version, I want to fix the code before I setup the text shown perfectly.
In this situation, you would use a loop. Loops repeat a block of code until either the loop condition returns false or the loop is broken out of through other means.
while true do
term.clear()
term.setCursorPos(1, 1)
print("Enter password")
pass = read("*")
if pass == "pass" then
print("Welcome")
sleep(2)
term.clear()
term.setCursorPos(1, 1)
break
else
print("Goodbye")
sleep(2)
end
end
When the password is correct, it calls the 'break' keyword. This keyword breaks out of the current loop.
17 posts
Posted 18 July 2013 - 06:33 AM
So I tried to make one but it doesn't seem to work, any help?
term.clear()
term.setCursorPos(1, 1)
print("Enter password")
pass = read("*")
if pass == "pass" then
print("Welcome")
sleep(2)
term.clear()
term.setCursorPos(1, 1)
else
print("Goodbye")
sleep(2)
shell.run(startup)
end
PS: This is an unfinished version, I want to fix the code before I setup the text shown perfectly.
In this situation, you would use a loop. Loops repeat a block of code until either the loop condition returns false or the loop is broken out of through other means.
while true do
term.clear()
term.setCursorPos(1, 1)
print("Enter password")
pass = read("*")
if pass == "pass" then
print("Welcome")
sleep(2)
term.clear()
term.setCursorPos(1, 1)
break
else
print("Goodbye")
sleep(2)
end
end
When the password is correct, it calls the 'break' keyword. This keyword breaks out of the current loop.
Worked perfectly, thanks.