set check is not working properly for a block

182 views
Skip to first unread message

Sahithi Mangena

unread,
Jan 19, 2022, 12:54:53 PM1/19/22
to blo...@googlegroups.com
Hello,
The issue we are facing is like we have added setcheck for our block and in the setcheck we have not given some 'x' blocks name but even though we have not given the name for it the first block is allowed to attach the 'x' block into it. 

so our first block options are like -- 
          Blockly.Blocks['rule'] = {
                init: function() {
                    this.appendDummyInput()
                        .appendField("Rule")
                        .appendField(new Blockly.FieldTextInput("tag"), "IDENTIFIER");

                    this.appendStatementInput("CONDITION")
                        .setCheck(["If","OR"])
                        .appendField("C");
                    this.appendStatementInput("ACTION")
                        .setCheck(["Action", "Rule"])
                        .appendField("A");
                    this.setPreviousStatement(true, ["Rule"]);
                    this.setNextStatement(true, ["Rule"]);
                    this.setColour('#8a69c8');
                    this.setTooltip('');
                    this.setHelpUrl('');
                }
            };
and our 'x' block which we don't want to attach to our first block is --
 Blockly.Blocks['x'] = {
              this.appendDummyInput()
                    .appendField("Filter")
                    .appendField(lhs_dropdown, 'OBJECT');

                this.setInputsInline(true);
                this.setPreviousStatement(true, ["Filter", "OR"]);
                this.setNextStatement(true, ["Filter", "OR"]);
                this.setColour('#e75959');
                this.setTooltip('');
                this.setHelpUrl('');
}
we are not getting why our 'x' block is attaching to the other block . can anyone please help us on this issue?

regards,
sahithi

Beka Westberg

unread,
Jan 20, 2022, 7:49:20 AM1/20/22
to blo...@googlegroups.com
Hello sahithi =)

Could you provide a picture of where it is connecting incorrectly? At first glance it seems like the 'x' block is defined so that it can connect to the first statement input of the 'rule' block, and not anywhere else. Is this correct? or do you not want it to connect anywhere at all?

The reason it seems the 'x' block can connect to the first statement input of the 'rule' block is because both of the relevant connections have an 'OR' check:

```
// rule block first input
.setCheck(["If","OR"])

// x block previous connection
this.setPreviousStatement(true, ["Filter", "OR"]);
```

Which allows them to connect. You can check out this blog post for more info about connection checks.

I hope that helps! If that doesn't solve your problem I'm happy to try to help more!
--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/CAKjwcim1pvnfAeG%2Bx3%2Bh_OJdzj%3DQMBCG0KyqMC2_S%2B7azbYJhQ%40mail.gmail.com.

Sahithi Mangena

unread,
Jan 20, 2022, 8:29:34 AM1/20/22
to blo...@googlegroups.com
Hi beka

Yes we won't the 'x' block to connect at first place of 'rule' block. So document you shared can help us to stop this connection ?

Regards,
Sahithi

Beka Westberg

unread,
Jan 20, 2022, 8:33:26 AM1/20/22
to blo...@googlegroups.com
Hi Sahithi,

That's correct, the blog post should (hopefully) help.

Basically, what you need to do is either change the check on your rule block, or on your x block:
```
// rule block first input
.setCheck(["If","OR"])

// x block previous connection
this.setPreviousStatement(true, ["Filter", "OR"]);
```

Two connections can connect if there is *at least one* string that exists in both of their check arrays. Or if at least one of the connections has an empty check array.

So the reason they can connect is that both arrays contain the "OR" string.

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

Reply all
Reply to author
Forward
0 new messages