55 posts
Location
Everywhere.
Posted 08 September 2012 - 10:46 PM
Ok, so im trying to build a comunication system, mosty to figure out rednet, that sends a message from computer A to B, over a short distance.
rednet.open("left")
print("What is your user name?")
user= read()
function receiver()
id,mess,dist=rednet.receive()
print(mess)
end
function sender()
print("Print your message. Use --for service commands.")
word = read()
sent= user..":"..word
rednet.send(!computernumbergoeshere!,sent,true) --no, its not like that when I run it
end
while true do
parallel.waitForAny(sender(),receiver())
end
This is what I have so far, but when I try to send a message, it just hangs. The other computer (running the same scrip) does not get anything.
Yes, the id numbers are right.
Any help?
10 posts
Posted 08 September 2012 - 10:48 PM
try changing rednet.receive() to rednet.receive(1)
55 posts
Location
Everywhere.
Posted 08 September 2012 - 10:51 PM
Nope, both still hang forever…..
10 posts
Posted 08 September 2012 - 10:55 PM
try remove the true from rednet.send()
55 posts
Location
Everywhere.
Posted 08 September 2012 - 10:57 PM
Odd, one got a message, but the other didnt, then they both just hung for ever……
12 posts
Posted 09 September 2012 - 03:42 AM
ok two options here… I was just looking through my script I wrote (and got working correctly) earlier and there's only two differences so…
Try this first and don't mind my formatting changes, just the way I do my scripts :D/>/>
Spoiler
function receiver()
id, mess, dist = rednet.receive()
print(mess)
end
function sender()
print("Print your message. Use --for service commands.")
word = read()
sent = user..":"..word
rednet.send(!computernumbergoeshere!,sent)
end
rednet.open("left")
print("What is your user name?")
user= read()
while true do
parallel.waitForAny(sender, receiver)
end
If that doesn't work (really the only thing I did was removed the () from your two function calls) then try this one:
Spoiler
function receiver()
while true do
id, mess, dist = rednet.receive()
print(mess)
end
end
function sender()
while true do
print("Print your message. Use --for service commands.")
word = read()
sent = user..":"..word
rednet.send(!computernumbergoeshere!,sent)
end
end
rednet.open("left")
print("What is your user name?")
user= read()
while true do
parallel.waitForAny(sender, receiver)
end
The changes here are I'm not just looping the parallel call but also the functions it's calling in the first place. Otherwise, other than aesthetic differences and I'm handling the rednet open differently they're nearly the same.
992 posts
Posted 09 September 2012 - 04:15 AM
when using parallels you don't sent the result of a function you send the function as a variable basically leave the () off.
I have made corrections and modifications to make it run a little better. there is a cap on threads at 50 so making new threads every time would pass that cap quickly simple solution is to make a loop in the threads and keep running the same ones.
rednet.open("left")
print("What is your user name?")
user= read()
print("what ID you are "..os.getComputerID())
nID = tonumber(read())
function receiver()
while true do
local event,sender,message,distance = os.pullEvent("rednet_message")
term.setCursorPos(1,1)
term.clearLine()
print("MES : "..message)
end
end
function sender()
while true do
term.setCursorPos(1,2)
term.clearLine()
print("Print your message. Use --for service commands.")
term.clearLine()
word = read()
sent = user..":"..word
rednet.send(nID,sent,true) --no, its not like that when I run it
end
end
term.clear()
parallel.waitForAny(sender,receiver)
print("you should never see this")
55 posts
Location
Everywhere.
Posted 09 September 2012 - 04:18 PM
I still get odd errors. I think im going to scrap this code, and change what I want it to do. The send recevice system aint worth the effort. (was originaly going to turn into a message board.)