7 posts
Posted 05 May 2013 - 01:23 PM
Hey
I've a problem i would make a computer wich can output a redstone signal by typing a password in the computer.
This should look like this:
when I type pass1, Output 1 will activated (for example "right"
when I type pass2 ,Output 2 will activated (for example "left"
when I type pass3 ,Output 3 will activated (for example "back"
And when I type something other Output 4 (for example "bottom") will be activated
[attachment=1145:2013-05-05_19.18.09.png]
Is this possible?
If Yes can someone help me? :)/>
Sorry for my bad english
1548 posts
Location
That dark shadow under your bed...
Posted 05 May 2013 - 03:00 PM
local tAnswers={zxcv="right", KaoS="left", arbl="back"}
while true do
term.clear()
term.setCursorPos(1,1)
write("Password: ")
local pass=read()
for k,v in pairs(tAnswers) do
rs.setOutput(v,false)
end
rs.setOutput("bottom", false)
rs.setOutput(tAnswers[pass] or "bottom",true)
end
passwords are zxcv, KaoS and arbl, it's in a while loop so it will keep cycling
Edited on 05 May 2013 - 01:00 PM
194 posts
Location
Spain
Posted 05 May 2013 - 03:55 PM
Yes, it's possible, here is an example:
--'Here we define the passwords'
local pass1 = "testPass"
local pass2 = "anotherPass"
local pass3 = "pass3"
--'This is an infinite loop for our program'
while true do
--'Clear the screen and set the cursor position'
term.clear()
term.setCursorPos(1,1)
--'Ask the user to enter a password'
print("Please, enter a password:")
userPass = read("*") --'this function will replace entered chars with *'s so people can't see what you are writing.'
--'Now we set all the output to false, so if there is already a redstone signal on we will stop it.'
for _, side in pairs(rs.getSides()) do
rs.setOutput(side, false) --'rs.setOutput sets the redstone output in the side specified, we will see this later'
end --'end of our loop'
--'No we check if the user entered a valid password'
if userPass == pass1 then --'if the user writes testPass...'
rs.setOutput("right", true) --'set output in side "right" to true'
elseif userPass == pass2 then
rs.setOutput("left", true)
elseif userPass == pass3 then
rs.setOutput("back", true)
else --'if the user didn`t type the right password'
rs.setOutput("bottom", true)
end
end
Hope this help you
7 posts
Posted 05 May 2013 - 04:06 PM
thanks
7 posts
Posted 06 May 2013 - 09:20 AM
It says in the 9th line
\/
for _, side in pairs(rs.getSides()) do
<name> expected
7508 posts
Location
Australia
Posted 06 May 2013 - 09:29 AM
It says in the 9th line
\/
for _, side in pairs(rs.getSides()) do
<name> expected
I suggest using the version make by KaoS, it is FAR more extensible, streamlined, and efficient.
If you disregard my above suggestion, make sure that you have typed it right and there are no typos.
194 posts
Location
Spain
Posted 06 May 2013 - 10:20 AM
It says in the 9th line
\/
for _, side in pairs(rs.getSides()) do
<name> expected
I suggest using the version make by KaoS, it is FAR more extensible, streamlined, and efficient.
If you disregard my above suggestion, make sure that you have typed it right and there are no typos.
Yes, kaos solution is better but as he don't know how to make a password program I supposed that he don't understand the table stuff, so I made the same program but with a simpler Lua.
1548 posts
Location
That dark shadow under your bed...
Posted 06 May 2013 - 02:22 PM
Thanks BIT :)/> and thanks for getting the capitalization right lol.
wahok: diegodan1893's code should work perfectly, If you find it easier to understand please use it. Check the spelling of that line and if that is fine and it still doesn't work please give us a copy of your code along with your CC version
7 posts
Posted 06 May 2013 - 03:24 PM
I've found the error:
I've ignored the space.. now it works fine thanks for all
7508 posts
Location
Australia
Posted 06 May 2013 - 09:59 PM
Thanks BIT :)/> and thanks for getting the capitalization right lol.
Np :)/> of course I'm going to get the capitalization right, I can't rage at people when they get mine wrong, and then turn around and do it to others.
"Do unto others as you would have them do to you" — Golden Rule