FieldVariable "New Variable" option

170 views
Skip to first unread message

Joshua Lowe

unread,
Sep 25, 2024, 9:24:32 AM9/25/24
to Blockly
Hi all,

I believe that older versions of Blockly used to have a "New Variable" option within the dropdown list for FieldVariable.

Is there a flag to re-enable this within V11, or, a recommended way to add such an option?

Screenshot 2024-09-25 at 14.23.32.png

Beka Westberg

unread,
Sep 25, 2024, 8:40:53 PM9/25/24
to Blockly
Hello,

I don't think there's an easy way to reenable this sadly :/ I wasn't able to find the exact commit where it was removed, but variables haven't had this option for at least 8 years. Your best bet would be to create a custom field that's a subtype of `FieldVariable`, and override the `dropdownCreate` method.

I hope that gives you somewhere to start!
--Beka

feni...@google.com

unread,
Sep 27, 2024, 12:55:24 PM9/27/24
to Blockly
Hi Josh,

FYI one of the drivers for removing this option was the addition of types to variables. Adding types and the possibility of having multiple variable types in a single dropdown made it tricky to be clear about what would be created without a complex modal. We switched to having an explicit button for creating variables in the flyout.

I suspect you don't need to worry about that since you're doing python, but it may come up if you have any sort of type hinting.

Cheers,
Rachel

fu6...@gmail.com

unread,
Sep 29, 2024, 4:10:46 AM9/29/24
to Blockly
Hello,

I have successfully added the  "ADD VARIABLE" option to the dropdown menu. Here is my example.
You need to modify several parts of the code.

blockly_compressed.js  
Code 1  
Code 2
Code 3
Code 4

en.js

Best Wishes

fu6...

feni...@google.com 在 2024年9月28日 星期六凌晨12:55:24 [UTC+8] 的信中寫道:
ADD_VARIABLE.mp4

fu6...@gmail.com

unread,
Sep 29, 2024, 12:06:24 PM9/29/24
to Blockly
Hi, 

I have also successfully re-enable colour blocks within V11.


COLOUR.png

Best Wishes

fu6...

fu6...@gmail.com 在 2024年9月29日 星期日下午4:10:46 [UTC+8] 的信中寫道:

Joshua Lowe

unread,
Oct 1, 2024, 8:29:07 AM10/1/24
to Blockly
Thanks all!

I've managed to add the Create Variable option by following the example from Makecode's blockly upgrade project. I'll make sure to credit their work for this one!
Message has been deleted

fu6...@gmail.com

unread,
Oct 1, 2024, 11:50:36 AM10/1/24
to Blockly
Hi jl...,

Thank you for providing such excellent reference materials. As a result, I was able to resolve a long-standing issue and correct some errors in my sample codes. Unfortunately, I do not have an in-depth understanding of the JavaScript language, so I am not capable of extending the functionality by writing plugins.ortunately, I do not have an in-depth understanding of the JavaScript language, so I am not capable of extending the functionality by writing plugins.
fu6...

jl...@anaconda.com 在 2024年10月1日 星期二晚上8:29:07 [UTC+8] 的信中寫道:
Reply all
Reply to author
Forward
0 new messages