Modem API

Functionmodem.close
Closes a channel on a modem. A channel must be open to receive messages from it. A modem can only have 128 channels open at the same time. channel must be a number between 0 and 65535.
Syntax modem.close(
  • channel : number
)
Returns nil
Part of CC:Tweaked (source)
API modem
ExampleClose channel 42
Close channel 42.
Code
<nowiki>
local modem = peripheral.find("modem")
modem.close(42)
    </nowiki>
Functionmodem.closeAll
Closes all channels on a modem. A channel must be open to receive messages on it. A modem can only have 128 channels open at the same time.
Syntax modem.closeAll()
Returns nil
Part of CC:Tweaked (source)
API modem
ExampleClose all channels
Close all channels.
Code
<nowiki>
local modem = peripheral.find("modem")
modem.closeAll()
    </nowiki>
Functionmodem.isOpen
Checks if a channel is open. A channel must be open to receive messages on it. A modem can only have 128 channels open at the same time. channel must be a Number between 0 and 65535.
Syntax modem.isOpen(
  • channel : number
)
Returns boolean open
Part of CC:Tweaked (source)
API modem
ExampleCheck if channel 42 is open
Check if channel 42 is open.
Code
<nowiki>
local modem = peripheral.find("modem")
print(modem.isOpen(42))
    </nowiki>
Output
true
Functionmodem.isWireless
Returns whether the modem is wireless.
Syntax modem.isWireless()
Returns boolean isWireless
Part of CC:Tweaked (source)
API modem
ExampleCheck whether a modem is a wireless modem
Checks whether a modem is a wireless modem.
Code
<nowiki>
local modem = peripheral.find("modem")
print(modem.isWireless())
    </nowiki>
Output
true
Functionmodem.open
Opens a channel on a modem. A channel must be opened to receive messages from it. A modem can only have 128 channels open at the same time. channel must be a number between 0 and 65535.
Syntax modem.open(
  • channel : number
)
Returns nil
Part of CC:Tweaked (source)
API modem
ExampleOpen channel 42
Open channel 42.
Code
<nowiki>
local modem = peripheral.find("modem")
modem.open(42)
    </nowiki>
Functionmodem.transmit
Sends a modem message to a certain channel. If the modem is wired this will queue a modem_message event on all computers connected to the wired network that have the specified channel open. If the modem is wireless it will queue a modem_message event on all computers in range that have the specified channel open.  Note: To send a message the channel it is being sent from does not need to be open.
Syntax modem.transmit(
  • channel : number
  • replyChannel : number
  • message : any
)
Returns nil
API modem
ExampleSend a message on channel 42
Sends a "Hello World" on channel 42.
Code
<nowiki>
local modem = peripheral.find("modem")
modem.transmit(42, 43, "Hello World")
    </nowiki>
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.