A little about me before I get on to posting the code. I'm 19, graduated from HS 2 years ago and started college but had to move so now I'm not in school and I haven't programmed in 3 years. Anyway now that you're all bored here's the code.
Spoiler
local cursorX = 1 --This is supposed to be a simple host/client chatroom program, so if it seems like it, it is.
local cursorY = 1 --I'll try to explain some of the parts
local hostID = 0
local clientID = 0
local username = tostring(hostID)
local cMessage = ""
local hMessage = ""
local letter = ""
local shift = false
function ClearScreen() --Nobody likes typing this s**t over and over again so I declared a function.
term.clear()
term.setCursorPos(1,1)
end
function AnyEvent() --The purpose of this program is to allow your program to keep running while accepting input. I don't
event, param1, param2 = os.pullEvent() --like how io.read() halts your program and in a chatroom this command is
Decode() --useless as you can't recieve new messages until you've pressed enter/return.
end
function Decode() --This is how the program is supposed to decode os.pullEvent() events and prepare them for sending.
if event == "key" and param1 == "42" and shift == false then shift = true --Allows shift key functionality.
elseif event == "key" and param1 == "42" and shift == true then shift = false
end
if event == "char" and param1 == "1" and shift == false then letter = "1" --Lots of code here but it's all exactly the same.
elseif event == "char" and param1 == "2" and shift == false then letter = "2"
elseif event == "char" and param1 == "3" and shift == false then letter = "3"
elseif event == "char" and param1 == "4" and shift == false then letter = "4"
elseif event == "char" and param1 == "5" and shift == false then letter = "5"
elseif event == "char" and param1 == "6" and shift == false then letter = "6"
elseif event == "char" and param1 == "7" and shift == false then letter = "7"
elseif event == "char" and param1 == "8" and shift == false then letter = "8"
elseif event == "char" and param1 == "9" and shift == false then letter = "9"
elseif event == "char" and param1 == "0" and shift == false then letter = "0"
elseif event == "char" and param1 == "1" and shift == true then letter = "!" --Added a little part to test shift key, doesn't work.
elseif event == "char" and param1 == "2" and shift == true then letter = "@"
elseif event == "char" and param1 == "3" and shift == true then letter = "#"
elseif event == "char" and param1 == "4" and shift == true then letter = "$"
elseif event == "char" and param1 == "5" and shift == true then letter = "%"
elseif event == "char" and param1 == "6" and shift == true then letter = "^"
elseif event == "char" and param1 == "7" and shift == true then letter = "&"
elseif event == "char" and param1 == "8" and shift == true then letter = "*"
elseif event == "char" and param1 == "9" and shift == true then letter = "("
elseif event == "char" and param1 == "0" and shift == true then letter = ")"
elseif event == "char" and param1 == "a" and shift == false then letter = "a"
elseif event == "char" and param1 == "b" and shift == false then letter = "b"
elseif event == "char" and param1 == "c" and shift == false then letter = "c"
elseif event == "char" and param1 == "d" and shift == false then letter = "d"
elseif event == "char" and param1 == "e" and shift == false then letter = "e"
elseif event == "char" and param1 == "f" and shift == false then letter = "f"
elseif event == "char" and param1 == "g" and shift == false then letter = "g"
elseif event == "char" and param1 == "h" and shift == false then letter = "h"
elseif event == "char" and param1 == "i" and shift == false then letter = "i"
elseif event == "char" and param1 == "j" and shift == false then letter = "j"
elseif event == "char" and param1 == "k" and shift == false then letter = "k"
elseif event == "char" and param1 == "l" and shift == false then letter = "l"
elseif event == "char" and param1 == "m" and shift == false then letter = "m"
elseif event == "char" and param1 == "n" and shift == false then letter = "n"
elseif event == "char" and param1 == "o" and shift == false then letter = "o"
elseif event == "char" and param1 == "p" and shift == false then letter = "p"
elseif event == "char" and param1 == "q" and shift == false then letter = "q"
elseif event == "char" and param1 == "r" and shift == false then letter = "r"
elseif event == "char" and param1 == "s" and shift == false then letter = "s"
elseif event == "char" and param1 == "t" and shift == false then letter = "t"
elseif event == "char" and param1 == "u" and shift == false then letter = "u"
elseif event == "char" and param1 == "v" and shift == false then letter = "v"
elseif event == "char" and param1 == "w" and shift == false then letter = "w"
elseif event == "char" and param1 == "x" and shift == false then letter = "x"
elseif event == "char" and param1 == "y" and shift == false then letter = "y"
elseif event == "char" and param1 == "z" and shift == false then letter = "z"
elseif event == "key" and param1 == "1" then letter = "message received!" --Little rednet testing.
--(Early signs of a chat program)
end
end
ClearScreen() --One line of code.
while true do --Two lines of code.
term.write(letter) --Three lines of code.
AnyEvent() --Four lines of code.
end --Five lines of code. (Yes it counts because without it your program will not work.)
I'll explain the error I'm having but putting the script on an in-game computer might help more. I guess my syntax is all okay since I can run the program, but when I try to give it input, the first time i press a button it's okay, it outputs normally, but when you hit another button it will print out again the last letter you typed and the new letter. I really just can't figure it out. Hopefully some fresh eyes will be able to help. Thanks in advance, guys.
EDIT: I think I messed up the commenting, sorry. I'll figure it out and fix it right away.