create list block with a default number of inputs

171 views
Skip to first unread message

Javier JM

unread,
Apr 30, 2021, 7:39:50 AM4/30/21
to Blockly
Hello,
I am creating a list using newBlock('lists_create_with') but I would like the list to have only 1 input instead of 3. How could I change the default number of inputs.
I tried to set the itemCount_ property to 1
myBlock.itemCount_ = 1;
but it doesn't work. It seems the init function is called afterwards and itemCount_ is set back to 3

Thank you very much for your help
J.

Beka Westberg

unread,
Apr 30, 2021, 4:33:32 PM4/30/21
to blo...@googlegroups.com
Hello,

If you're trying to create a specific block (especially one with a specific mutation!) I recommend deserializing it from XML. This makes sure that all of the block's state gets set up correctly.

For example:
```
var block = Blockly.Xml.domToBlock(Blockly.
this.block = Blockly.Xml.domToBlock(Blockly.Xml.textToDom(
    '<block type="lists_create_with"><mutation items="3"></mutation></block>'
), this.workspace);
```

I hope that helps! If you have any further questions please reply,
--Beka

--
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/2fda3eb8-3616-42c0-b338-3b1d360992aen%40googlegroups.com.

Javier JM

unread,
May 1, 2021, 3:01:33 AM5/1/21
to Blockly
Thank you so much Beka!
Now it works!
J.

Reply all
Reply to author
Forward
0 new messages