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

*SOLVED* [Lua][Question] Getting "false" from rednet.send() when used inside a program

Started by foxxx0, 11 July 2012 - 03:45 PM
foxxx0 #1
Posted 11 July 2012 - 05:45 PM
Hey guys,

I have some issues with rednet.send() when I use that command inside a lua program. However, when I open the lua console and write the command there everything is fine.

Test setup:

server <-> client

server tasks:
loops forever on os.pullEvent("rednet_message"), sends response whether received command was valid or not (for later use).

client tasks:
sends command to server and waits for ACK.

server:

local rnetSource = "left" -- rednet input from left
rednet.open(rnetSource) -- enable receiving
while true do
event, sender, message = os.pullEvent("rednet_message") -- wait for event to happen
print("msg from #" .. sender .. ": " .. message)
print(rednet.send(sender, "got your message"))
end
rednet.close(rnetSource)

client:

local rnetSource = "back" -- rednet input from back
local target = 11 -- serverID
rednet.open(rnetSource) -- enable receiving
sleep(5)
print(rednet.send(target, "Test msg"))
event, sender, message = os.pullEvent("rednet_message")
print("msg from #" .. sender .. ": " .. message)
rednet.close(rnetSource)


The issue: As you probably see I put the rednet.send() commands inside a print() command to debug its return value. For the client everything works great, but the server rednet.send() however returns "false".
If I sequence the commands manually inside the lua prompt -> everything works ?!

So, if anyone could explain me, why my server is unable to send rednet messages inside programs, I would be really happy. A possible solution/workaround is also welcome.

greetings,
foxxx0

PS: I'm from Germany so please excuse mistakes in language :)/>/>
MysticT #2
Posted 11 July 2012 - 05:59 PM
I only see one error, and it's on the client:

print(rednet.send(taget, "Test msg"))
A simple typo, it should be:

print(rednet.send(target, "Test msg"))

For the server, make sure the modem if on the left side, cause there's no other way for it to return false.
foxxx0 #3
Posted 11 July 2012 - 06:07 PM
Hm not sure how this happened, maybe error from c&amp;p as I cutted some of the code and shrinked it together.

In fact, the message is arriving at the server:
> server
msg from #25: Test msg
false

As you can see, the rednet.send command returns false. Also I am not using wireless modems, the Computers are connected through redpower jacketed cables (bundled) as they have to travel some distance for later use and the config option modem_range had no effect for me, set it to 512 but still no receiving after 64 blocks of distance.

client:
> client
true

And there is the deadlock, client waiting for a rednet_message-event that did not and won't happen as the server was unable to send that message.
MysticT #4
Posted 11 July 2012 - 06:14 PM
The message gets to the server because it's broadcasting (because taget is nil). But anyway, sending over bundled cables is different, the problem might be that the port is still busy when you try to send the message. Try with:

rednet.send(sender, "got your message", true)
So it waits till the port is open. Also make sure that there's nothing interfering with the communication, like something setting a cable on the bundle on.
foxxx0 #5
Posted 11 July 2012 - 06:21 PM
The message gets to the server because it's broadcasting (because taget is nil). But anyway, sending over bundled cables is different, the problem might be that the port is still busy when you try to send the message. Try with:

rednet.send(sender, "got your message", true)
So it waits till the port is open. Also make sure that there's nothing interfering with the communication, like something setting a cable on the bundle on.

Thanks man, that "true" paramter fixed it.

Should probably be added here: http://computercraft.info/wiki/index.php?title=Rednet.send so I would have found it :)/>/>

I'm looking very carefully in the documentation of each command as I am used to it, but if there's nowhere explained that rednet.send() accepts a third parameter how should i know?


Thanks again for that, now I can continue the work on my "train station switching system" ^^


PS: Do you got an idea why my wireless modems won't accept a higher range set in mod_ComputerCraft.cfg ?
MysticT #6
Posted 11 July 2012 - 06:27 PM
You'r right, it should be on the wiki. I got that reading the api code, if you see the function definition:

function send( nRecipient, sMessage, bWaitUntilPortOpen )
It's pretty obious what it does :)/>/>

For the modem range, knowing the forge and CC versions you use will help solve it. You should make a post in the bugs forum, I'm sure Cloudy will know what's the problem B)/>/>
foxxx0 #7
Posted 11 July 2012 - 06:31 PM
Ah there I can find that. Now I know where else I can search around :)/>/>

Thanks for the advice, I will open a bug thread for my other problem.

–> thread can be closed and marked as *solved* if there is anything like that in here <–
vipes2010 #8
Posted 29 August 2012 - 03:57 AM
You'r right, it should be on the wiki. I got that reading the api code, if you see the function definition:

function send( nRecipient, sMessage, bWaitUntilPortOpen )
It's pretty obious what it does :D/>/>

For the modem range, knowing the forge and CC versions you use will help solve it. You should make a post in the bugs forum, I'm sure Cloudy will know what's the problem :P/>/>

Thanks, this solved my problems with rednet over bundled cables. :P/>/> I added this argument to the Wiki. http://computercraft...tle=Rednet.send