How to access selected value of dynamically generated drop down menu

30 views
Skip to first unread message

Barbara Schütt

unread,
Feb 3, 2023, 4:52:56 PM2/3/23
to Blockly
Hi,

I have a dynamically created drop down menu. It is a list of actors, and every time a new actor is added this drop down menu is updated (during runtime). In JSON it is defined as this:

{
"type": "input_dummy",
"name": "actor_drop_down",
},

So there is no drop down menu there. It is generated during runtime and I can find it with
block_withDDMenu.getInput('actor_drop_down')
But somehow this is different from when it is defined with

"type": "field_dropdown",
"name": "EXAMPLE",
"options": [
[
...
]

During runtime, every time an actor is added, removed or changed, this menu is created and updated in the blocks needing this information.

How can I access this "actor_drop_down" structure in a code generator of a block that has such a dynamic list of actors? The method

block_withDDMenu.getFieldValue('actor_drop_down')

only returns null (since I think it is not properly defined in JSON)?

Do you need more information?

Best regards and thanks
Barbara


Barbara Schütt

unread,
Feb 6, 2023, 4:36:49 PM2/6/23
to Blockly
I was now able to get it with
block.getInput('FIELD_NAME').fieldRow[1].selectedOption_[0]

is there a more elegant way of doing this?

Mark Friedman

unread,
Feb 6, 2023, 8:52:04 PM2/6/23
to blo...@googlegroups.com
I believe that block.getField('FIELD_NAME').getValue() might be a little more elegant.

-Mark


--
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/ae6ad7b4-18f5-4d33-a480-497ecab7aca4n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages