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

input = read() issue

Started by ryarsh, 09 November 2012 - 06:06 AM
ryarsh #1
Posted 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/>/>
digpoe #2
Posted 09 November 2012 - 07:09 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/>/>
I belive you should try using a different name, such as:

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
PixelToast #3
Posted 09 November 2012 - 07:09 AM
-snip-
Edited on 09 November 2012 - 06:15 AM
PixelToast #4
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 :s
digpoe #5
Posted 09 November 2012 - 07:13 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 :s
Oh thanks, I didn't notice at the time… Although, I don't usually do that. Must've been me, being stupid.
ryarsh #6
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
digpoe #7
Posted 09 November 2012 - 07:17 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
I just put it in CODE tags to read easier.
ryarsh #8
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
digpoe #9
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!
ryarsh #10
Posted 09 November 2012 - 07:28 AM
Sorry :/ im new here
ryarsh #11
Posted 09 November 2012 - 07:28 AM
sorry im new here
PixelToast #12
Posted 09 November 2012 - 07:31 AM
change input = read("*") to input = read()
digpoe #13
Posted 09 November 2012 - 07:32 AM
Don't be sorry that you're new, we were all new once!
ryarsh #14
Posted 09 November 2012 - 07:43 AM
but then if i typed Lab then it woudlnt show as ***
ryarsh #15
Posted 09 November 2012 - 07:44 AM
so, digpoe do you know how to fix my issue?
digpoe #16
Posted 09 November 2012 - 07:44 AM
so, digpoe do you know how to fix my issue?
I posted a fix at the top. Simply use different variable names and it should work.
Cloudy #17
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").
ryarsh #18
Posted 09 November 2012 - 07:54 AM
Didn't work :/
Cloudy #19
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")
ryarsh #20
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
Lyqyd #21
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.
Lyqyd #22
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.
Mandrake Fernflower #23
Posted 09 November 2012 - 09:29 AM
We need a rule against spagettti code
civilwargeeky #24
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
 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)
civilwargeeky #25
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.
Lyqyd #26
Posted 09 November 2012 - 02:32 PM
Threads merged. Previous posts may be in a confusing order.
rhyleymaster #27
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