288 posts
Location
The trashcan where all Undertale trash is
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()
1688 posts
Location
'MURICA
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".
288 posts
Location
The trashcan where all Undertale trash is
Posted 29 August 2012 - 10:56 PM
Thank you and sorry. I'll try that. :)/>/>
288 posts
Location
The trashcan where all Undertale trash is
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()
14 posts
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.
1688 posts
Location
'MURICA
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.
288 posts
Location
The trashcan where all Undertale trash is
Posted 30 August 2012 - 12:02 AM
Ok, it works now! Thank you for your help!
288 posts
Location
The trashcan where all Undertale trash is
Posted 30 August 2012 - 12:44 AM
Oh great, now the menu is broken. What is wrong with it, you think?
1688 posts
Location
'MURICA
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.
288 posts
Location
The trashcan where all Undertale trash is
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