How to set value Dynamically from one block to another block?

69 views
Skip to first unread message

Naresh Chaudhari

unread,
Mar 12, 2021, 7:20:35 AM3/12/21
to Blockly
Hi @all, 
Is it possible to get a value from the specific block and set the same value to another block? 

Here is my block...

Capture.PNG

For example, I have three blocks as a class block, execute block, and init block. If I type the class name as "testsuiteResultTopology" in the class block, then instead of "default" text same class name should be fill/display/appear automatically in execute block and init block. How can I do it? 

Please help me to share any idea/Example/code.







Naresh Chaudhari

unread,
Mar 12, 2021, 7:28:03 AM3/12/21
to Blockly
It is like: Write class name Once and use it multiple times / anywhere in the workspace. 

Beka Westberg

unread,
Mar 12, 2021, 3:17:33 PM3/12/21
to blo...@googlegroups.com
Hello,

That's definitely possible, but it's probably more work than it is worth. The issue that comes to mind with a system like this is that it's going to run into a lot of edge cases. For example, what if someone edits the "class name <default>" text input manually? Do you ignore the change, or do you change the class name above? If you want to use the name elsewhere in the workspace, the same problem applies.

Here are a few options you might want to consider instead:
  • Combine the "execute" block with the "class" block so you don't have to worry about matching the text.
  • Only have the text input field in the "class" block, and use label fields (which you update programmatically) in other places. This is what the function blocks do.
  • Use variable fields for your class names (variable fields handle updates automatically)
But if you do want to use text inputs in all places, you should either use validators or event listeners to trigger updates. You can then use the field.setValue function to manually set the value of your "mirror" text input fields. Here are some things that might be good reference as you're building out this system:
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/235584a4-2420-401b-b205-bf6fc4f4d763n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages