How could I get the ChunkOrVariableID of the blocks on VM?

Issue #470 resolved
Tom Ming created an issue

@John Maloney

I would like to commucate with MicroBlocks VM according to SERIAL_PROTOCOL.md.

I read the SERIAL_PROTOCOL.md ,it says :

Long message format (5 + dataSize bytes):

[0xFB, OpCode, ChunkOrVariableID, DataSize-LSB, DataSize-MSB, ...data...]

How do I know the ChunkOrVariableID that a specific blocks corresponds to a specific chunkID or VariableID?

For example :

I could commucate with the hat blocks No. 2 and No. 3 using web Bluetooth API of HTML5.

It seems that the ChunkID of the blocks No. 2 and No. 3 is 0, is that true?

Is it possiable to commucate with the blocks No. 1 and No. 4 using web Bluetooth API of HTML5.

How could I get the ChunkOrVariableID of the blocks No. 1 and No. 4?

Thanks.

BR

Tom

Comments (6)

  1. John Maloney repo owner

    The chunk ID's for scripts are assigned by the IDE as scripts are created. There isn't any easy way to predict how they are assigned.

    If your goal is to create a remote-control system, I would take a different approach using broadcasts.

    You might start by putting each script you want to trigger under a "when _ received" hat block. You can then use the serial protocol to send "broadcast" (OpCode: 0x1B, long message) messages to the board to trigger those scripts.

    If you'd like to send parameters as well, you might look at the "Going Further" section of this wiki article. That article uses a Snap! library to send and receive broadcast messages over the serial protocol, but it would be easy to port that library to other languages such as Python or Javascript.

    I like this approach because it is simple yet flexible. The model is simple -- the client and the MicroBlocks program simply send text messages to each other using broadcast. One can use string operations to construct and parse messages. Since the messages are human-readable strings, one can debug problems more easily.

  2. Log in to comment