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

Rednet Program, Table not working

Started by CastleMan2000, 29 August 2012 - 08:45 PM
CastleMan2000 #1
Posted 29 August 2012 - 10:45 PM
Hello, I currently am working on RRC, Rednet Relay Chat. Basically, a very simple send/receive program. For some reason, it's complaining about my table. Here's the code. I made it in repl.it.

Spoiler

--RednetRelayChat: RRC
screenx, screeny = term.getSize()
currenty = 1
rrc = {
	send = function()
		term.setCursorPos(2, screeny - 2)
		write(">: ")
		input = read()
		rednet.broadcast(input)
	end
	recv = function()
		term.setCursorPos(currentx, currenty)
		id, msg = rednet.receive()
		print(id .." >: " .. msg)
	end
	menu = function()
		print [[
RRC 1.0

		A. Enter RRC
		B. Exit
]]
		write("What will you do? >: ")
		binput = read()
		if binput == "a" or "A" then
			term.clear()
			while true do
				parallel.waitForAny(send(), recv())
			end
		elseif binput == "b" or "B" then
			error()
	end
}
rednet.open("right")
rrc.menu()
Kingdaro #2
Posted 29 August 2012 - 10:51 PM
You should have a semicolon at the end of each of your ends in the table.

Also, next time, providing the actual error it's giving is better than just saying "it's complaining".
CastleMan2000 #3
Posted 29 August 2012 - 10:56 PM
Thank you and sorry. I'll try that. :)/>/>
CastleMan2000 #4
Posted 29 August 2012 - 11:01 PM
Now it says:
"bios:206: [string "RRC"]:34: unexpected symbol"

Updated code:
Spoiler

--RednetRelayChat: RRC
screenx, screeny = term.getSize()
currenty = 1
rrc = {
	send = function()
		term.setCursorPos(2, screeny - 2)
		write(">: ")
		input = read()
		rednet.broadcast(input)
	end;
	recv = function()
		term.setCursorPos(currentx, currenty)
		id, msg = rednet.receive()
		print(id .." >: " .. msg)
	end;
	menu = function()
		print [[
RRC 1.0

		A. Enter RRC
		B. Exit
]]
		write("What will you do? >: ")
		binput = read()
		if binput == "a" or "A" then
			term.clear()
			while true do
				parallel.waitForAny(send(), recv())
			end
		elseif binput == "b" or "B" then
			error()
	end;
}
rednet.open("right")
rrc.menu()
Andybish #5
Posted 29 August 2012 - 11:51 PM
:34: in the error message means the error is on line 34, but according to this code, line 34 is rednet.open("right"), so either the error is wrong, your editing program creates an invisible character that CC doesn't recognize, or this isn't all the code you've used in the computer.
Kingdaro #6
Posted 30 August 2012 - 12:01 AM
One of your ifs is missing an end. The last one I believe, after the elseif in the function rrc.menu.
CastleMan2000 #7
Posted 30 August 2012 - 12:02 AM
Ok, it works now! Thank you for your help!
CastleMan2000 #8
Posted 30 August 2012 - 12:44 AM
Oh great, now the menu is broken. What is wrong with it, you think?
Kingdaro #9
Posted 30 August 2012 - 01:03 AM
Probably because you have a "while true do" loop without a way of breaking out of it.

If you entered "a" you would be perpetually stuck until you terminated the program.
CastleMan2000 #10
Posted 30 August 2012 - 03:28 AM
Oh. Well, I should probably put a sleep(0) in there, eh? Thing is, B doesn't work either.

edit: now also gives an 'unexpected symbol' error on line 35