This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
input = read() issue
Started by ryarsh, 09 November 2012 - 06:06 AMPosted 09 November 2012 - 07:06 AM
i have a problem i want one input = read("*") to hide the input as " which is fine and works but then after i have the input = read("*") i have another input = read() were i do NOT want the input to be shown as * but it seems it still shows as * any help would be appreciated thanks, if code is needed then i can post it i suppose. ty :P/>/>
Posted 09 November 2012 - 07:09 AM
I belive you should try using a different name, such as:i have a problem i want one input = read("*") to hide the input as " which is fine and works but then after i have the input = read("*") i have another input = read() were i do NOT want the input to be shown as * but it seems it still shows as * any help would be appreciated thanks, if code is needed then i can post it i suppose. ty :P/>/>
input = read("*")
if input = "TEST" then
print "Access granted. Please type the seccondary password."
local newinp = read()
if newinp = "TEST2" then
print "Access granted! You can now proceed.
end
end
Posted 09 November 2012 - 07:09 AM
-snip-
Edited on 09 November 2012 - 06:15 AM
Posted 09 November 2012 - 07:11 AM
EDIT:
local input = read("*")
if input == "TEST" then
print("Access granted. Please type the seccondary password.")
local newinp = read()
if newinp == "TEST2" then
print("Access granted! You can now proceed.")
end
end
fixed syntax errors :sPosted 09 November 2012 - 07:13 AM
Oh thanks, I didn't notice at the time… Although, I don't usually do that. Must've been me, being stupid.EDIT:fixed syntax errors :slocal input = read("*") if input == "TEST" then print("Access granted. Please type the seccondary password.") local newinp = read() if newinp == "TEST2" then print("Access granted! You can now proceed.") end end
Posted 09 November 2012 - 07:16 AM
hi thanks, here is the code i want the input when i type Help to just type Help and not change it to **** please do not inprove my code, im just learning and want to correct my own mistakes thanks! :P/>/>
term.clear()
term.setCursorPos(1, 1)
print("Loading…")
print("1: Enter access password: ")
print("2: Help")
term.write("Command…")
input = read("*")
if input == "Lab" then
print("Lab access granted")
rs.setOutput("bottom", true)
term.write("Door in open state, type Close to finish: ")
input = read()
elseif input == "Help" then
print("Please type password")
sleep(3)
term.clear()
term.setCursorPos(1, 1)
print("Reloading…")
print("1: Enter access password: ")
print("2: Help")
input = read("*")
if input == "Lab" then
print("Lab access granted")
rs.setOutput("bottom", true)
term.write("Door in open state, type Close to finish: ")
input = read()
if input == "Close" then
rs.setOutput("bottom", false)
sleep(3)
os.shutdown(1)
else
print("Incorrect")
sleep(3)
print("Shuttingdown")
sleep(2)
print("3")
sleep(1)
print("2")
sleep(1)
print("1")
sleep(1)
os.shutdown(1)
end
end
end
term.clear()
term.setCursorPos(1, 1)
print("Loading…")
print("1: Enter access password: ")
print("2: Help")
term.write("Command…")
input = read("*")
if input == "Lab" then
print("Lab access granted")
rs.setOutput("bottom", true)
term.write("Door in open state, type Close to finish: ")
input = read()
elseif input == "Help" then
print("Please type password")
sleep(3)
term.clear()
term.setCursorPos(1, 1)
print("Reloading…")
print("1: Enter access password: ")
print("2: Help")
input = read("*")
if input == "Lab" then
print("Lab access granted")
rs.setOutput("bottom", true)
term.write("Door in open state, type Close to finish: ")
input = read()
if input == "Close" then
rs.setOutput("bottom", false)
sleep(3)
os.shutdown(1)
else
print("Incorrect")
sleep(3)
print("Shuttingdown")
sleep(2)
print("3")
sleep(1)
print("2")
sleep(1)
print("1")
sleep(1)
os.shutdown(1)
end
end
end
Posted 09 November 2012 - 07:17 AM
I just put it in CODE tags to read easier.hi thanks, here is the code i want the input when i type Help to just type Help and not change it to **** please do not inprove my code, im just learning and want to correct my own mistakes thanks! :P/>/>term.clear() term.setCursorPos(1, 1) print("Loading...") print("1: Enter access password: ") print("2: Help") term.write("Command...") input = read("*") if input == "Lab" then print("Lab access granted") rs.setOutput("bottom", true) term.write("Door in open state, type Close to finish: ") input = read() elseif input == "Help" then print("Please type password") sleep(3) term.clear() term.setCursorPos(1, 1) print("Reloading...") print("1: Enter access password: ") print("2: Help") input = read("*") if input == "Lab" then print("Lab access granted") rs.setOutput("bottom", true) term.write("Door in open state, type Close to finish: ") input = read() if input == "Close" then rs.setOutput("bottom", false) sleep(3) os.shutdown(1) else print("Incorrect") sleep(3) print("Shuttingdown") sleep(2) print("3") sleep(1) print("2") sleep(1) print("1") sleep(1) os.shutdown(1) end end end
Posted 09 November 2012 - 07:21 AM
hi , here is the code i want the input when i type Help to just type Help and not change it to **** please do not inprove my code, im just learning and want to correct my own mistakes thanks! :P/>/>
term.clear()
term.setCursorPos(1, 1)
print("Loading…")
print("1: Enter access password: ")
print("2: Help")
term.write("Command…")
input = read("*")
if input == "Lab" then
print("Lab access granted")
rs.setOutput("bottom", true)
term.write("Door in open state, type Close to finish: ")
input = read()
elseif input == "Help" then
print("Please type password")
sleep(3)
term.clear()
term.setCursorPos(1, 1)
print("Reloading…")
print("1: Enter access password: ")
print("2: Help")
input = read("*")
if input == "Lab" then
print("Lab access granted")
rs.setOutput("bottom", true)
term.write("Door in open state, type Close to finish: ")
input = read()
if input == "Close" then
rs.setOutput("bottom", false)
sleep(3)
os.shutdown(1)
else
print("Incorrect")
sleep(3)
print("Shuttingdown")
sleep(2)
print("3")
sleep(1)
print("2")
sleep(1)
print("1")
sleep(1)
os.shutdown(1)
end
end
end
term.clear()
term.setCursorPos(1, 1)
print("Loading…")
print("1: Enter access password: ")
print("2: Help")
term.write("Command…")
input = read("*")
if input == "Lab" then
print("Lab access granted")
rs.setOutput("bottom", true)
term.write("Door in open state, type Close to finish: ")
input = read()
elseif input == "Help" then
print("Please type password")
sleep(3)
term.clear()
term.setCursorPos(1, 1)
print("Reloading…")
print("1: Enter access password: ")
print("2: Help")
input = read("*")
if input == "Lab" then
print("Lab access granted")
rs.setOutput("bottom", true)
term.write("Door in open state, type Close to finish: ")
input = read()
if input == "Close" then
rs.setOutput("bottom", false)
sleep(3)
os.shutdown(1)
else
print("Incorrect")
sleep(3)
print("Shuttingdown")
sleep(2)
print("3")
sleep(1)
print("2")
sleep(1)
print("1")
sleep(1)
os.shutdown(1)
end
end
end
Posted 09 November 2012 - 07:23 AM
Please don't make multiple topics about the same script. It's best to just stick to the one topic. If we don't reply, then we could be busy coding or doing somthing else. Don't assume we've forgotten about your thread and left it to gather dust!
Posted 09 November 2012 - 07:28 AM
Sorry :/ im new here
Posted 09 November 2012 - 07:28 AM
sorry im new here
Posted 09 November 2012 - 07:31 AM
change input = read("*") to input = read()
Posted 09 November 2012 - 07:32 AM
Don't be sorry that you're new, we were all new once!
Posted 09 November 2012 - 07:43 AM
but then if i typed Lab then it woudlnt show as ***
Posted 09 November 2012 - 07:44 AM
so, digpoe do you know how to fix my issue?
Posted 09 November 2012 - 07:44 AM
I posted a fix at the top. Simply use different variable names and it should work.so, digpoe do you know how to fix my issue?
Posted 09 November 2012 - 07:53 AM
That isn't the issue.
You're trying to accept "Help" like a password - there will be no way for the read command to detect what you're typing before you type it. If you mean you want to change it back to Help after enter has been pressed, move the cursor pos and write("Help").
You're trying to accept "Help" like a password - there will be no way for the read command to detect what you're typing before you type it. If you mean you want to change it back to Help after enter has been pressed, move the cursor pos and write("Help").
Posted 09 November 2012 - 07:54 AM
Didn't work :/
Posted 09 November 2012 - 08:00 AM
Didn't work :/
Didn't work how?
Personally how I'd do it is this:
input = read("*")
-- check if input is Help succeeded
local x, y = term.getCursorPos()
y = y - 1
term.setCursorPos(1, y)
write("Help")
Posted 09 November 2012 - 08:48 AM
Edit:
term.clear()
term.setCursorPos(1, 1)
print("Loading…")
print("1: Enter access password: ")
print("2: Help")
term.write("Command…")
input = read("*")
if input == "Lab" then
print("Lab access granted")
rs.setOutput("bottom", true)
sleep(2)
term.write("Door in open state, type Close to finish: ")
input = read()
if input == "Close" then
sleep(1)
rs.setOutput("bottom", false)
sleep(2)
os.shutdown(2)
input = read()
if input == "Help" then
print("Please type password")
sleep(3)
term.clear()
term.setCursorPos(1, 1)
print("Reloading…")
sleep(3)
term.clear()
term.setCursorPos(1, 1)
print("1: Enter access password: ")
print("2: Help")
input = read("*")
if input == "Lab" then
print("Lab access granted")
rs.setOutput("bottom", true)
sleep(2)
term.write("Door in open state, type Close to finish: ")
sleep(1)
input = read()
if input == "Close" then
rs.setOutput("bottom", false)
sleep(3)
os.shutdown(1)
else
print("Incorrect")
sleep(3)
print("Shuttingdown")
sleep(1)
os.shutdown(1)
term.write("Door in open state, type Close to finish: ")
input = read()
if input == "Close" then
rs.setOutput("bottom", false)
sleep(3)
os.shutdown(1)
else
print("Incorrect")
sleep(3)
print("Shuttingdown")
sleep(2)
print("3")
sleep(1)
print("2")
sleep(1)
print("1")
sleep(1)
os.shutdown(1)
end
end
end
end
end
so the problem im having is when i type Lab then type Close lab activates the door well, but then when i type Close the door wont close everything else works fine, anyone ideas>? thanks
term.clear()
term.setCursorPos(1, 1)
print("Loading…")
print("1: Enter access password: ")
print("2: Help")
term.write("Command…")
input = read("*")
if input == "Lab" then
print("Lab access granted")
rs.setOutput("bottom", true)
sleep(2)
term.write("Door in open state, type Close to finish: ")
input = read()
if input == "Close" then
sleep(1)
rs.setOutput("bottom", false)
sleep(2)
os.shutdown(2)
input = read()
if input == "Help" then
print("Please type password")
sleep(3)
term.clear()
term.setCursorPos(1, 1)
print("Reloading…")
sleep(3)
term.clear()
term.setCursorPos(1, 1)
print("1: Enter access password: ")
print("2: Help")
input = read("*")
if input == "Lab" then
print("Lab access granted")
rs.setOutput("bottom", true)
sleep(2)
term.write("Door in open state, type Close to finish: ")
sleep(1)
input = read()
if input == "Close" then
rs.setOutput("bottom", false)
sleep(3)
os.shutdown(1)
else
print("Incorrect")
sleep(3)
print("Shuttingdown")
sleep(1)
os.shutdown(1)
term.write("Door in open state, type Close to finish: ")
input = read()
if input == "Close" then
rs.setOutput("bottom", false)
sleep(3)
os.shutdown(1)
else
print("Incorrect")
sleep(3)
print("Shuttingdown")
sleep(2)
print("3")
sleep(1)
print("2")
sleep(1)
print("1")
sleep(1)
os.shutdown(1)
end
end
end
end
end
so the problem im having is when i type Lab then type Close lab activates the door well, but then when i type Close the door wont close everything else works fine, anyone ideas>? thanks
Posted 09 November 2012 - 08:55 AM
You simply can't have it both ways. The only possibility would be to create a custom read() that shows asterisks for the entire string if it isn't "Help" or a subset of that string.
Posted 09 November 2012 - 09:03 AM
Stop making new topics for the same chunk of code. That's three topics now, two of which are completely unnecessary and just add clutter.
Posted 09 November 2012 - 09:29 AM
We need a rule against spagettti code
Posted 09 November 2012 - 01:25 PM
I don't know what you're talking about. It works just fine for me. I just ran it and it worked as intended (I guess)
It said
It said
Loading...
1: Enter access password:
2: Help
Command...[then I typed Lab here, and the asterisks came up]
Lab access granted
Door in open state, type Close to finish: [I typed Close here]
> [program ended]
You might want to incase the whole thing in a while true do loop, because as of now it only runs once (or twice if you get it wrong)Posted 09 November 2012 - 01:29 PM
Oh wait. I misunderstood the problem.
No, you can't do that, unless you made a custom function that wouldn't type asterisks if you started with "H." It will always type asterisks, no matter what is there.
No, you can't do that, unless you made a custom function that wouldn't type asterisks if you started with "H." It will always type asterisks, no matter what is there.
Posted 09 November 2012 - 02:32 PM
Threads merged. Previous posts may be in a confusing order.
Posted 09 November 2012 - 07:07 PM
You could try like this:
write("Username:")
local user = read()
if user == (username)
then
write("Password:")
local pass = read("*")
if pass == (password)
then
print("Access Granted.")
else
print("Access Denied.")
end
else
write("Password:")
local fpass = read("*")
if fpass == ()
then
print("Access Denied.")
else
print("Access Denied.")
You can see, You should have indents between breaks in large codes