There's some errors in the code:
Change this:
web = read()
if string.lower(web) == "right" or "left" or "top" or "bottom" or "back" or "front" then
to:
local web = string.lower(read())
if web == "right" or web == "left" or web == "top" or web == "bottom" or web == "back" or web == "front" then
You should add an else here:
write("Welcome to Chatter! a simple-to-use chatting program. The commands are: Exit (Shuts the computer down)")
else -- add this
rednet.broadcast(ans) -- I think i just found my first error...
So it broadcasts the text if it's not a command.
For the receiver:
while true do
id, msg = rednet.receive()
write(msg) --I don't think this works either...
end
But it will just print every received message and never exit.
To make all work at the same time, you have to choose one of the options I said before:
- Use the parallel API, it's included in CC (type help parallel to learn more about it):
To use this API, you need to create two functions: one to send and one to receive. Then you just do:
parallel.waitForAny(send, receive) -- send and receive are the functions you need to create
The send function would read the message and then send it, and the receive function would wait for a rednet message and show it on the screen.
The problem with this is that the functions may write on the same place of the screen, so you need some way to make sure that doesn't happen (like making the send function write on the last line).
- Handle the events, the user input and message send/receive yourself:
You need a loop that gets the events and handles each of them. The events you need to handle would be: key and char (for user input) and rednet_message (to get the received messages). It can be a little bit more complex since you have to store the user input, concatenate the entered keys and send the message when the user presses enter (everything that read() does), but you have more control over the program.
I would use the second option (I actually used it on my chat program), but it can be a little harder to start with.
Try some of this and come back with any question you have.