Block.data property lost

106 views
Skip to first unread message

lingareddy kotanka

unread,
Apr 12, 2023, 3:23:06 AM4/12/23
to Blockly
Hello Team,

I created custom blocks using JOSN format and want to add some data to it(meta data), so i make use of 'data' property in block.
as used in docs:
https://developers.google.com/blockly/guides/create-custom-blocks/define-blocks?hl=en#block_data

after setting some value, when i try to access the data property is set to null. 
Could you please assist on this?
const start_stop = [
      {
        "type": "outputBlock",
        "lastDummyAlign0": "CENTRE",
        "message0": "Output",
        "previousStatement": null,
        "tooltip": "",
        "helpUrl": "",
        "style": "inputOutput",
        "data": "some value"
      }
    ];
Blockly.defineBlocksWithJsonArray(start_stop);

Neil Fraser

unread,
Apr 12, 2023, 5:14:34 AM4/12/23
to blo...@googlegroups.com
Small point of confusion: The 'data' property is part of the JSON and XML save formats, not a part of the JSON block definition formats.

There's no need for a 'data' property in the block definition since 'type' will be unique anyway.

Does that make sense?


--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/ecbbf422-ce2a-4b61-bb31-c0f11e1abe9cn%40googlegroups.com.


--
Neil Fraser, Switzerland
https://neil.fraser.name
Message has been deleted
Message has been deleted

Mark Friedman

unread,
Apr 12, 2023, 3:50:57 PM4/12/23
to blo...@googlegroups.com
Lingareddy,

  I believe that Neil's point is that the data property that you would be specifying would be the same for all blocks of the type (e.g. "outputBlock") that you are defining.  Consequently, rather than having it be a property of the block, it could just be a constant, based on the block type, and referenced as such in your renderer.  If it turns out that the metadata is really per block, rather than per block type, you would just set it directly on the block via code.

-Mark


On Wed, Apr 12, 2023 at 12:38 PM lingareddy kotanka <ikot...@gmail.com> wrote:

Hello Team,

Okay, so is there any way we can attach some metadata to block definition?
because i will need that info in my custom renderer class to define some constants based on it.

Thank you
Reply all
Reply to author
Forward
0 new messages