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

Rednet.receive()

Started by orik1997, 22 April 2015 - 04:43 PM
orik1997 #1
Posted 22 April 2015 - 06:43 PM
Hi I have encountered a problem whilest working with my script I want to receive an encoded message which I then seperate into multiple strings that works fine the only problem I have is that my program won't move past the line:
senderID, message, protocol = rednet.receive()
I have defined all three variables before and I don't get an error the code just stops the next line would be print ("worked") it never gets activated.
KingofGamesYami #2
Posted 22 April 2015 - 06:47 PM
That would indicate it isn't receiving a message. Check that you have rednet.open, and a modem attached, and are sending a message after the program has started.

If this doesn't help, post the code of both scripts involved.
Square789 #3
Posted 22 April 2015 - 06:51 PM
rednet.receive() waits until it gets a message from rednet (modems),
so make sure that you have added
rednet.open(modem_side)
to the code
But how does the code ,,stop" ? Does it shutdown the Computer, does it wait so you can't make an input or does it hang up?
Edited on 22 April 2015 - 05:18 PM
InDieTasten #4
Posted 22 April 2015 - 07:00 PM
rednet.receive() waits until it gets a message from rednet (wired modems(maybe wireless modems, I don't know)),
so make sure that
  • You right-click the modem so it turns red and you can read ,,Peripheral "computer_x" connected to network"
  • add ,,rednet.open(modem_side)" to the code
  • Wrap the modem as a peripheral with mod = peripheral.wrap(modem_side) and mod.open()
Why would you want to make any of his computers available as peripheral? The only line he might have forgotten is rednet.open(side)
Either that, or he isn't sending messages at all or in the correct time frame (while the receive function waits) or is sending messages to the wrong computer.
In any case, if the help provided by now doesn't help him, we need his code.

Also, @orik1997 I would recommend to read the pinned topics in the forums in any section you are writing something ;)/>
It will make everyones life easier, trust me ;)/>
Square789 #5
Posted 22 April 2015 - 07:15 PM
Why would you want to make any of his computers available as peripheral? The only line he might have forgotten is rednet.open(side)
Either that, or he isn't sending messages at all or in the correct time frame (while the receive function waits) or is sending messages to the wrong computer.
In any case, if the help provided by now doesn't help him, we need his code.

Also, @orik1997 I would recommend to read the pinned topics in the forums in any section you are writing something ;)/>
It will make everyones life easier, trust me ;)/>

Yes, I'm not that experienced with computers interacting with each other, so maybe I even shouldn't have replied to this topic…
edited my post
Edited on 22 April 2015 - 05:15 PM
orik1997 #6
Posted 22 April 2015 - 07:49 PM
Ok this is the code of the receiving computer: http://pastebin.com/yb61xTH8
It's 232 lines long though I wait for the rednet.receive at line 222 and I open the rednet at line 193. The Computers ID is 4.
And the sending code is 2 lines long it's:
rednet.open("right")
rednet.send(4,"Miner%10%9%27%minecraft:diamond_ore%4%")
InDieTasten #7
Posted 22 April 2015 - 08:47 PM
Which "hardware" of Computercraft are you using? Can you confirm, that the modem is actually opened, since it's in a place, that can be skipped by the script at some condition?

I think the problem might lies in the architecture of your "load" system. Passing a table to function will AFAIK create a copy of that table locally defined within the function. So all your stuff you try to load is erased after the load function completes. (I'm not too sure with this, though) Then you might have to return the tables your load function creates and store them in the same table, when calling to "load" like mytable = load(yourfilethingies, mytable).

If it does actually open the modem, are you in valid range to the sender?
When using wireless, distance is set in the mod config.
When using network cables, be sure all cable sections lie in chunks that are loaded, and the distance does not exceed 256 blocks.
Edited on 22 April 2015 - 06:49 PM
orik1997 #8
Posted 22 April 2015 - 08:51 PM
The wireless Modem is active and the load function works since I can print out the different elements in the table.
orik1997 #9
Posted 22 April 2015 - 09:04 PM
Ok sorry guys I got confused I had a networking cable connected to the computer I'm sorry for wasting your time.
Lyqyd #10
Posted 22 April 2015 - 10:14 PM
I think the problem might lies in the architecture of your "load" system. Passing a table to function will AFAIK create a copy of that table locally defined within the function. So all your stuff you try to load is erased after the load function completes. (I'm not too sure with this, though) Then you might have to return the tables your load function creates and store them in the same table, when calling to "load" like mytable = load(yourfilethingies, mytable).

This is entirely wrong. Tables "values" are just references to the table. If you pass a table to a function (or return one from a function), both references point to the same table.