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

Need help with my program

Started by Txereas, 23 January 2014 - 10:42 AM
Txereas #1
Posted 23 January 2014 - 11:42 AM
Hello. I have been working on a program essentially acting as a password lock. I have it set up so a menu appears asking what user they are letting you move the selection with the keyboard. There are three options with there usernames. Two out of the three will send a prompt to a second computer asking if they should be allowed to enter which then sends a prompt back saying If they have permission to enter or not. The problem im having is when I select one of the users, the menu glitches out and starts listing random names. Btw: I have the second computer with its own script which seems to run without error. Here is a link to pastebin: http://pastebin.com/n1dMypib
Edited on 23 January 2014 - 11:58 AM
OReezy #2
Posted 23 January 2014 - 01:16 PM
I've been looking over your code and there are a few issues I have found.

1. selection will never be equal to "Option" because your menu function returns the names you input. So change the strings to the names of the people.
2. In Option1(), term.Clear() should not be capitalized.
3. When you send a rednet message you send it to 0 which errors Not an issue
4. When your code loops, it doesn't reset its position. When it reaches the bottom of the screen it makes your menu function act oddly and the program becomes unusable.

This last two aren't necessary, but can make your code smaller.

You can open the modem once in your program and leave it on, unless you are worried about it getting messages from other computers and your other computer is reacting slowly.(which it should be nearly instant)

Option2() and Option3() are the same function with different variables. You can get rid of one of them if you pass it the string you want it to use.
local function hi(name)
  print("hello "..name)
  rendet.send(1,name)
end
Edited on 23 January 2014 - 07:17 PM
Lyqyd #3
Posted 23 January 2014 - 02:29 PM
The third problem you state isn't actually an issue. Computer 0 can use rednet just like any other computer.
Txereas #4
Posted 23 January 2014 - 02:53 PM
OReezy,
Thanks for all your help. The string names slipped right by me. I fixed everything you listed except for creating a function for the names. Could you help me understand how to impliment the names into that function? Also, I got the computer to the point where it asks the master computer yes or no but when i choose an answer the screen just turns black. Script for the User logins: http://pastebin.com/J947LXDQ
Script for master computer: http://pastebin.com/V7qfH0XD
Edited on 23 January 2014 - 02:28 PM
OReezy #5
Posted 23 January 2014 - 03:39 PM
OReezy,
Thanks for all your help. The string names slipped right by me. I fixed everything you listed except for creating a function for the names. Could you help me understand how to impliment the names into that function? Also, I got the computer to the point where it asks the master computer yes or no but when i choose an answer the screen just turns black. Script for the User logins: http://pastebin.com/J947LXDQ
Script for master computer: http://pastebin.com/V7qfH0XD

It is the same as your menu function. You can pass an argument to your function when you call it. For a basic example, if you wanted to make a function that printed an input and sent it over rednet to a certain computer, it would look like this:
local function send(arg, id)
  print(arg)
  rednet.send(id, arg)
end

send("hello", 5)  --> prints: hello  and sends "hello" to computer 5

You can send variables this way too. so if you had input = "John", send(input, 5) would do the same but print and send "John" instead.

EDIT: Tested the computer 0 thing and found it wasn't that part erroring. Thanks Lyqyd.
Edited on 23 January 2014 - 02:51 PM
Txereas #6
Posted 23 January 2014 - 03:56 PM
But I still don't understand why the code has an error sending back. The code used ( rednet.send(id, "") ) should work for sending something back. In the code I need the master computer to send either Yes or No back and then display the printed message I have there on the master computer.
Txereas #7
Posted 23 January 2014 - 06:07 PM
But i still don't understand why the code i have is erroring. The code from the master computer script recieves the promt to let them in or not but when I select yes or no the screen turns black and doesnt send anything. it is suppose to either send Yes or No depending what i chose, Then, ON THE SAME COMPUTER print Letting in or preparing defenses. Please take a look at the pastebin links from my last reply.
OReezy #8
Posted 23 January 2014 - 08:19 PM
I think you're asking about your other code you linked. Its the same issue as the first code. menu() returns "yes" or "no" so it will never be equal to "Option X"