←  Ask a Pro

ComputerCraft | Programmable Computers for Minecraft

»

Sending bits over modem

cmdpwnd's Photo cmdpwnd 24 Jun 2015

When sending data, it is sent as a string in rednet. Firstly, does this not apply when sending soley from the modem instead of via rednet? Second if no, is it still possible to send bits of data without it being interpreted as a byte?
Quote

Bomb Bloke's Photo Bomb Bloke 24 Jun 2015

Lua offers a limited selection of types compared to most other languages; strings, numbers, booleans, tables, functions, coroutines, and nil. Per the wiki, you can send any of these types directly via modems, with the exception of functions and coroutines (which get translated to nil). (Though to be fair, that was only documented there a bit over a week ago.)

So yeah, if you specifically want to send bools, just send bools.

modem.transmit(targetChannel, suggestedReplyChannel, true)

Edit:

It's important to note that modem messages arrive as events on the eligible destination systems. Events are pulled from the front of the event queue (each time a system yields by eg calling os.pullEvent()), and new events are added to the end. Each such system can only handle up to 256 events in their queue at a time. That means that if you're sending data one bit per message, there is an absolute upper limit of just 32 bytes before you either allow the target system to start pulling events, or before you start losing data - and odds are the "in practise" figure will be lower, because the modem_message events aren't going to be the only ones populating the queue.

Likewise, if you eg transmit two messages for every one that's getting pulled, the queue will quickly overflow and you'll start losing information.
Edited by Bomb Bloke, 24 June 2015 - 06:19 AM.
Quote

Lyqyd's Photo Lyqyd 24 Jun 2015

And you can send all of those types through the rednet API functions just as well as you can via the raw modem peripheral function.
Quote

cmdpwnd's Photo cmdpwnd 24 Jun 2015

ok, but the bool value `true` while specifies a state is still 4bytes long, so in the event that I send `true` is it sent as 4bytes or if not, what is it sent as and how long is it?
Quote

Lyqyd's Photo Lyqyd 24 Jun 2015

It doesn't matter. All of those details are abstracted away on the Java side of things. A Boolean will send and be received just as fast as a ten kilobyte string, or a large table.
Quote