Jump to content




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

lua networking

7 replies to this topic

#1 foxxx0

  • New Members
  • 6 posts

Posted 11 July 2012 - 04: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 :)/>

#2 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 11 July 2012 - 04: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.

#3 foxxx0

  • New Members
  • 6 posts

Posted 11 July 2012 - 05:07 PM

Hm not sure how this happened, maybe error from c&p as I cutted some of the code and shrinked it together.

In fact, the message is arriving at the server:

Quote

> 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:

Quote

> 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.

#4 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 11 July 2012 - 05: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.

#5 foxxx0

  • New Members
  • 6 posts

Posted 11 July 2012 - 05:21 PM

View PostMysticT, on 11 July 2012 - 05:14 PM, said:

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...tle=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 ?

#6 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 11 July 2012 - 05: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)/>

#7 foxxx0

  • New Members
  • 6 posts

Posted 11 July 2012 - 05: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 <--

#8 vipes2010

  • New Members
  • 3 posts

Posted 29 August 2012 - 02:57 AM

View PostMysticT, on 11 July 2012 - 05:27 PM, said:

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users