11 posts
Posted 11 March 2016 - 12:03 PM
Alright so two things I have been stuck on for a couple day's, Tables and Rednet.
I am currently trying to make a simple door lock with a few features. Username, password, user input attempts ( 0 / 3 ).
The script won't recognize the second input just the first, I could put the correct username and incorrect pass and it will say access granted.
Also I tried to add the time along with it but when I put a while true do loop I can't enter any input. Obviously i'm doing somethan wrong but I don't know what.
If anyone could setup a small script for me to have as an example to work with that would be awesome.
Rednet, I'm actually almost got it working but got stopped by the while true do loop.
The sender worked by waiting for user input and then send it to the receiver. Once received it will display on to the monitor.
This is the issue I was having with that. If I we're to put that loop in the receiver end it wouldn't work the script would stop.
If I sent a message to the receiver it would display "Hello" at pos(1,1) if I were to send a second message it would overlap it.
I would share the code but… the computer went bye bye into the air thanks to my jackass of a friend so atm I am starting from scratch.
While I start over hopefully someone could answer my two questions, I'll post either later today or tomorrow my progress.
Oh and by the way if you say "Have you looked at the wiki for answers" YES. I researched a'lot actually but obviously what people posted wasn't exactly what I was looking for or they didn't explain it better.
3057 posts
Location
United States of America
Posted 11 March 2016 - 02:13 PM
For a door lock with attempts, I'd do this:
--#create a table where the keys are the usernames and the values associated with them are the passwords
--#allows you to easily add other users if you wish
local tUsers = {
["KingofGamesYami"] = "password1",
}
--#define a number for max attempts.
local max_attempts = 3
for i = 1, max_attempts do --#loop this 3 times
print( "Attempt #" .. i ) --#print which input attempt you're on
write( "Username: " ) --#ask for username / password
local username = read()
write( "Password: " )
local password = read( "*" )
if tUsers[ username ] == password then --#if the user entered their password
--#open the door
return --#exit the program
end
end
print( max_attempts .. " incorrect attempts were made!" )
--#do whatever you want to happen if this occurs
As for rednet, you seem to understand how to do it. You might want to consider using term.redirect and print to display the information on the monitor though.
11 posts
Posted 12 March 2016 - 02:37 AM
For a door lock with attempts, I'd do this:
--#create a table where the keys are the usernames and the values associated with them are the passwords
--#allows you to easily add other users if you wish
local tUsers = {
["KingofGamesYami"] = "password1",
}
--#define a number for max attempts.
local max_attempts = 3
for i = 1, max_attempts do --#loop this 3 times
print( "Attempt #" .. i ) --#print which input attempt you're on
write( "Username: " ) --#ask for username / password
local username = read()
write( "Password: " )
local password = read( "*" )
if tUsers[ username ] == password then --#if the user entered their password
--#open the door
return --#exit the program
end
end
print( max_attempts .. " incorrect attempts were made!" )
--#do whatever you want to happen if this occurs
As for rednet, you seem to understand how to do it. You might want to consider using term.redirect and print to display the information on the monitor though.
Thank you yami it works great and compact. Here is the finished code for now.
-- Door Lock for Server Room
local tUsers = {
["nukeinmypantz"] = "thecakeisalie"
}
local max_attempts = 3
function main()
for i = 1, max_attempts do
term.clear()
term.setCursorPos(1,1)
print("Attempt #" .. i )
term.setCursorPos(1,3)
write("Username: ")
term.setCursorPos(10,3)
local username = read()
term.setCursorPos(1,4)
write("Password:")
term.setCursorPos(10,4)
local password = read("*")
if tUsers[ username ] == password then
rs.setOutput("top", true)
sleep(6)
rs.setOutput("top", false)
return
end
end
term.setCursorPos(1,7)
print( max_attempts .. " incorrect attempts were made!")
print("Terminal locked for 10 seconds")
sleep(10)
main()
end
main()
Now that I have that done I am gonna go and try to finish the Rednet Chat System. I'll reply on this post if I have any more problems about Rednet or figured it out and post the Code so that anyone could see it and tell me if I need to fix somethan or make the script smaller.
11 posts
Posted 12 March 2016 - 03:10 AM
Hey KingofGamesYami do you know how to instead of typing in a char you can use the Up, Down, Left, Right Arrow Keys. Enter and Backspace to navigate menus. This is an extension for the script using username, password, debug, etc.
And I haven't found a good post about how to make the Advanced Monitor detect player interaction when left or right clicking.
I want to use the arrow keys for in the computer navigation and the monitor touchscreen for checking farm, server, anything else status. I can make the checking the farm stuff but I can't make Both Navigation for in the computer and monitor.
Computer: display Login, Debug, Commands, Status, Profile.
Monitor: display Login, Debug, Commands, Status, Profile. And is there a way to project a keyboard on to the monitor so instead of going into the computer and typing it in you could right click the monitor and type in your username & password ?
3057 posts
Location
United States of America
Posted 12 March 2016 - 03:25 AM
Yes, I do.
Advanced monitors can't detect the difference between right or left clicks.
I know someone's made a better version of a keyboard, but I can't find it right yet.
Mine's over here. It's pretty bad since I haven't touched it in two years, but I think it still works… I could re-write it to be so much better.
11 posts
Posted 12 March 2016 - 03:38 AM
Yes, I do.
Advanced monitors can't detect the difference between right or left clicks.
I know someone's made a better version of a keyboard, but I can't find it right yet.
Mine's over here. It's pretty bad since I haven't touched it in two years, but I think it still works… I could re-write it to be so much better.
Even if it doesn't work, it's a good starting point thank you. Do you know how to make a simple Navigation system using the up, down, left right, enter, backspace keys ?
I'm gonna mess around with the script tomorrow and see what I can do :)/> Thank you Yami.
3057 posts
Location
United States of America
Posted 12 March 2016 - 03:43 AM
In case I wasn't clear, that's what that is. It's a function that does all the fun stuff for you - drawing and erasing '[', generating multiple pages, etc. If you don't like the style, I made a
less intrusive one which is themed after the menu for the 'edit' program.