Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

block dispose

43 views
Skip to first unread message

Sahithi Mangena

unread,
Dec 19, 2024, 8:15:17 AM12/19/24
to blo...@googlegroups.com
Hello everyone,

We are trying to change one connection of a block from FieldTextInput to appendValueInput. And in this whatever the values previously saved with the textfield need to be appended as a new block to the same connections. So we are trying here with the following changes.

old block 
this.appendDummyInput("RHS_INPUT")
       .appendField(new Blockly.FieldTextInput("value"), "value");

converted the above to replace the value with a new block connection having the old value in it.

let newblock = Blockly.getMainWorkspace().newBlock('string_value_block');
                        newblock.setFieldValue(value, 'value');
         
this.appendValueInput('RHS_INPUT').connection.connect(newblock.outputConnection);
                        

In this way we are able to convert the old filedtextinput to the new string_value_block to get connected. 
But there is an issue with after the connection we are seeing in the workspace the string_value_block is available 2 in the input list of the blocks when used inputList on the workspace. How can we avoid the newblock to be added to workspace 2 times to the workspace.
We have tried the newblock.dispose(true) after using this the entire new connection of the block is getting deleted. So anyone can help here with this issue.

Thanks and regards,
sahithi



Confidentiality Warning:
This message and any attachments are intended only for the use of the intended recipient(s), are confidential, and may be privileged. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or other use of this message and any attachments is strictly prohibited. If received in error, please notify the sender immediately and permanently delete it.

Ronald Bourret

unread,
Dec 19, 2024, 7:25:19 PM12/19/24
to blo...@googlegroups.com
I don't have all your code, but I think I see what is happening. The problem is that your old code and your new code do two very different things.

Your old code defines a block. That is, I would expect to see this code in the init function of a block definition in Blockly.Blocks. This is the code that Blockly runs to instantiate a block, such as when you drag it from the toolbox to the workspace.

Your new code programmatically connects two blocks that are already in the workspace, but does so incorrectly. Assuming "this" refers to an existing block that already has a value input, your code adds a second value input (this.appendValueInput). This is why you see two value inputs in Block.inputList.

Here is the init function that defines a block that uses a value input instead of a text field. The user can connect a value block to this block.

Blockly.Blocks['my_rhs_input_block'] = {
  init: function() {
    this.appendValueInput('RHS_INPUT');
  }
}

On the other hand, if you want to programmatically connect a new string_value_block to a block that has a single value input, you would use the following code. Notice that we get the value input from Block.inputList.

let rhsInputBlock = Blockly.getMainWorkspace().newBlock('my_rhs_input_block');
let newblock = Blockly.getMainWorkspace().newBlock('string_value_block');
newblock.setFieldValue(value, 'value');
rhsInputBlock.inputList[0].connection.connect(newblock.outputConnection);

Ronald Bourret
Technical Writer (Provided by Synergis)


--
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 visit https://groups.google.com/d/msgid/blockly/CAKjwcimCJ_BDaA_VLaaDGp2zmX3P7oJRhmYFtS8PN8UJiousrg%40mail.gmail.com.

Christopher Allen

unread,
Dec 24, 2024, 6:04:23 PM12/24/24
to blo...@googlegroups.com
Hi Sahithi,

But there is an issue with after the connection we are seeing in the workspace the string_value_block is available 2 in the input list of the blocks when used inputList on the workspace.

I've read this a few times and unfortunately I'm not sure exactly what you mean—perhaps you could include some screenshots?—but if Ron has correctly understood you when he wrote:

 Assuming "this" refers to an existing block that already has a value input, your code adds a second value input (this.appendValueInput). This is why you see two value inputs in Block.inputList.

…then his advice is good, and I would only add that an alternative would be simply to delete the RHS_INPUT dummy input before appending a replacement value input of the same name.


Christopher

Reply all
Reply to author
Forward
0 new messages