Get inline blocks

44 views
Skip to first unread message

Rebecca Eiland

unread,
Jul 13, 2022, 3:13:49 PM7/13/22
to Blockly
I am trying to access the inner/inline blocks used as input to another block. Problem is, when I use .getChildren, it doesn't seem to keep track of what is in a specific spot. For instance, if I start with the blocks below, 
start.PNG

The num block with 3 in it is in position 0 of the array, and the 'if' block is in position 1. So I can initially access the inline block with block.getChildren()[0].type

However, if I put in a different block in place of the num block:
newinline.PNG
 it shifts the array so that the 'if' block is now in position 0, and the new block, the inline block, is in position 1. So now, block.getChildren()[0].type returns the .type of the 'if' block.

How do I get whatever block is attached in a specific spot? I need to be able to identify the inner blocks that don't get highlighted when the block it is attached to does get highlighted. It needs to be able to tell if there is an operation block vs a num block etc. and log it into the console. Even if I loop through the array, it doesn't help if the index of that spot keeps changing because I can't use the index to figure out where that block is at.
Below is an example of my code if it helps:

innerblockcode.PNG


Beka Westberg

unread,
Jul 14, 2022, 11:09:13 AM7/14/22
to blo...@googlegroups.com
Hello!

There are two options two achieve what you want =)

1) Pass `true` to getChildren, which sorts the children in order of the inputs.
2) Use getInputTargetBlock to get the block associated with a specific named input.

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/ab4937f8-4b41-446a-b4cf-5ba9b8903dben%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages