8 posts
Posted 21 November 2012 - 05:43 PM
function lock()
term.clear()
term.setCursorPos(1,1)
correctpass = "bitchboy"
development = "console"
write("Please Enter Passcode: ")
pass = read()
if pass == (correctpass) then
write("Access Granted!")
redstone.setOutput("right",true)
sleep(1)
redstone.setOutput("right",false)
os.reboot()
lock()
if pass == (development)
write("Console Opened!")
return
else
write("Access Denied!")
sleep(1)
os.reboot()
lock()
end
end
lock()
Ok, so this is my code so far, that is messed up. My whole goal for this code, is to access the CraftOS 1.3 by typing in "console" so you can change things without going to a seperate computer. I coded it like so above.
THE PROBLEM: Everything works great, but when i type in anything other the correctpass it uses the console command. I dont know why. The console command was only supposed to work if you typed "console" when it asks for the password, but if you type in anything aside from the correct password, it still uses the Console command. Sorry if i'm explaining horribly. Please help! Thanks in advance!
1111 posts
Location
Portland OR
Posted 21 November 2012 - 07:09 PM
It's better to use if elseif else end rather then two if statements. You're missing a then on the second if, and you also do not need the () around the vars in your if statements although I think it will work with them. Here is how I would do the if statement.
if pass == correctpass then
write("Access Granted!")
redstone.setOutput("right",true)
sleep(1)
redstone.setOutput("right",false)
os.reboot()
lock() <-- if this is your startup file you don't need this. It's not going to run after the reboot.
elseif pass == development then
write("Console Opened!")
return
else
write("Access Denied!")
sleep(1)
os.reboot()
lock() <-- if this is your startup file you don't need this. It's not going to run after the reboot.
end
Instead of the reboot, or calling the function from within itself(nesting, which will cause a stack overflow) try using a while loop.
Spoiler
correctpass = "bitchboy"
development = "console"
while true do
term.clear()
term.setCursorPos(1,1)
write("Please Enter Passcode: ")
pass = read()
if pass == correctpass then
write("Access Granted!")
redstone.setOutput("right",true)
sleep(1)
redstone.setOutput("right",false)
elseif pass == development then
write("Console Opened!")
break
else
write("Access Denied!")
sleep(1)
end
end
Edited on 21 November 2012 - 06:14 PM
8 posts
Posted 21 November 2012 - 07:54 PM
It's better to use if elseif else end rather then two if statements. You're missing a then on the second if, and you also do not need the () around the vars in your if statements although I think it will work with them. Here is how I would do the if statement.
if pass == correctpass then
write("Access Granted!")
redstone.setOutput("right",true)
sleep(1)
redstone.setOutput("right",false)
os.reboot()
lock() <-- if this is your startup file you don't need this. It's not going to run after the reboot.
elseif pass == development then
write("Console Opened!")
return
else
write("Access Denied!")
sleep(1)
os.reboot()
lock() <-- if this is your startup file you don't need this. It's not going to run after the reboot.
end
Instead of the reboot, or calling the function from within itself(nesting, which will cause a stack overflow) try using a while loop.
Spoiler
correctpass = "bitchboy"
development = "console"
while true do
term.clear()
term.setCursorPos(1,1)
write("Please Enter Passcode: ")
pass = read()
if pass == correctpass then
write("Access Granted!")
redstone.setOutput("right",true)
sleep(1)
redstone.setOutput("right",false)
elseif pass == development then
write("Console Opened!")
break
else
write("Access Denied!")
sleep(1)
end
end
Thank YOU SO MUCH! Its working!!!!!!!!! I LOVE YOU!
1214 posts
Location
The Sammich Kingdom
Posted 21 November 2012 - 08:42 PM
Who sets their password to "bitchboy"? Meh, my sister's facebook password is "Fuckaduck24" so I shouldn't be typing this message.
8 posts
Posted 22 November 2012 - 09:24 AM
Who sets their password to "bitchboy"? Meh, my sister's facebook password is "Fuckaduck24" so I shouldn't be typing this message.
I put bitchboy there for the post, thats not my real password lol
1214 posts
Location
The Sammich Kingdom
Posted 22 November 2012 - 11:01 AM
Who sets their password to "bitchboy"? Meh, my sister's facebook password is "Fuckaduck24" so I shouldn't be typing this message.
I put bitchboy there for the post, thats not my real password lol
I thought it was… I was getting kinda concerned about your security.