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

Using peripheral methods via wireless modem

Started by r05ty, 27 February 2016 - 02:27 PM
r05ty #1
Posted 27 February 2016 - 03:27 PM
Hello

I would like to make some sort of network with wireless modems to control my big reactor and turbines.

I'm thinking something like this - main computer will send message to computer connected to reactor:


-- hey activate that reactor
modem.transmit(1, 2, "setActive(true)")

This message will caught secondary computer


local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
-- message received, turning up
reactor.message() -- but actually is going to use "reactor.setActive(true)"

Thanks for your reply
HPWebcamAble #2
Posted 27 February 2016 - 09:35 PM
You can do it like this:

modem.transmit( 1,2, {"setActive",true} )


local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")

reactor[ message[1] ]( message[2] )

You'd send a table containing the method to call (as a string), and the value to pass it.

On the other end you index the method name in the reactor table, calling the function with the value specified in the message.
KingofGamesYami #3
Posted 28 February 2016 - 01:08 AM
Though it is fairly old, I believe you may benefit from using my wireless peripherals API. If nothing else, you could read through my code to see how you might accomplish something similar.
r05ty #4
Posted 01 March 2016 - 02:46 PM
Thanks for your answers.
I used solution of HPWebcamAble, and after some editing and troubleshooting I managed to make it work flawlessly.

To KingofGamesYami:
For my case I did something similiar, but with determining if its argument given or not.