Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » How to make number dropdowns functional?
- AmpElectrecuted
-
1000+ posts
How to make number dropdowns functional?
I am working on an update to ampmod, and want to use data_listindexall/random for the list blocks. However, if you click the dropdown, it goes into drag state regardless of whether you're holding the block. And if you switch tabs, all blocks before lists are gone. How do you make number dropdowns functional?
- Pufferfish_Test
-
500+ posts
How to make number dropdowns functional?
is the dropsown block in a <shadow> xml element/does it have shadow: true in the project.json? that should stop it from being draggable
- AmpElectrecuted
-
1000+ posts
How to make number dropdowns functional?
(#2)it is a shadow, the whole block is dragged. my numberdropdown file is the same as vanilla
is the dropsown block in a <shadow> xml element/does it have shadow: true in the project.json? that should stop it from being draggable
- Maximouse
-
1000+ posts
How to make number dropdowns functional?
The error message in the console tells you what's wrong: the getOptions() method is missing. To fix this, you can change this line in field_textdropdown.js:
to:
This will make the dropdown appear, but selecting an item in the dropdown still doesn't work, which can be fixed by addind an onItemSelected() method:
With correct JSDoc, the code should look like this:
Blockly.FieldTextDropdown.prototype.getOptions_ = Blockly.FieldDropdown.prototype.getOptions_;
Blockly.FieldTextDropdown.prototype.getOptions = Blockly.FieldDropdown.prototype.getOptions;
This will make the dropdown appear, but selecting an item in the dropdown still doesn't work, which can be fixed by addind an onItemSelected() method:
Blockly.FieldTextDropdown.prototype.onItemSelected = Blockly.FieldDropdown.prototype.onItemSelected;
With correct JSDoc, the code should look like this:
/** * Return a list of the options for this dropdown. * See: Blockly.FieldDropDown.prototype.getOptions. * @return {!Array.<!Array.<string>>} Array of option tuples: * (human-readable text, language-neutral name). */ Blockly.FieldTextDropdown.prototype.getOptions = Blockly.FieldDropdown.prototype.getOptions; /** * Handle the selection of an item in the dropdown menu. * See: Blockly.FieldDropDown.prototype.onItemSelected. * @param {!goog.ui.Menu} menu The Menu component clicked. * @param {!goog.ui.MenuItem} menuItem The MenuItem selected within menu. */ Blockly.FieldTextDropdown.prototype.onItemSelected = Blockly.FieldDropdown.prototype.onItemSelected;
- AmpElectrecuted
-
1000+ posts
How to make number dropdowns functional?
(#4)Doesn't seem to work. the blocks just disappear when i create a variable. Requiring utils and using it doesn't help either
The error message in the console tells you what's wrong: the getOptions() method is missing. To fix this, you can change this line in field_textdropdown.js:
-snip-
- Maximouse
-
1000+ posts
How to make number dropdowns functional?
I've only tested this in a vanilla Scratch fork – it's possible that TurboWarp changes something that makes it not work. Do any errors get printed to the console when the blocks disappear?(#4)Doesn't seem to work. the blocks just disappear when i create a variable. Requiring utils and using it doesn't help either
The error message in the console tells you what's wrong: the getOptions() method is missing. To fix this, you can change this line in field_textdropdown.js:
-snip-
- AmpElectrecuted
-
1000+ posts
How to make number dropdowns functional?
(#6)yeah
I've only tested this in a vanilla Scratch fork – it's possible that TurboWarp changes something that makes it not work. Do any errors get printed to the console when the blocks disappear?
just let me boot up my webpack server quickly
- AmpElectrecuted
-
1000+ posts
How to make number dropdowns functional?
(#7)The code kinda works because it doesn't drag the whole block with no escape anymore, but i still get:(#6)yeah
I've only tested this in a vanilla Scratch fork – it's possible that TurboWarp changes something that makes it not work. Do any errors get printed to the console when the blocks disappear?
just let me boot up my webpack server quickly
Uncaught TypeError: option is undefined
Last edited by AmpElectrecuted (March 12, 2025 07:53:02)
- Maximouse
-
1000+ posts
How to make number dropdowns functional?
I don't know where that could come from. Can you push the current version of your code (to a separate branch) so that I can try to debug it? The code kinda works because it doesn't drag the whole block with no escape anymore, but i still get:Uncaught TypeError: option is undefined
- AmpElectrecuted
-
1000+ posts
How to make number dropdowns functional?
Will do so when I get homeI don't know where that could come from. Can you push the current version of your code (to a separate branch) so that I can try to debug it? The code kinda works because it doesn't drag the whole block with no escape anymore, but i still get:Uncaught TypeError: option is undefined
- AmpElectrecuted
-
1000+ posts
How to make number dropdowns functional?
(#10)https://codeberg.org/AmpMod/scratch-blocks/src/branch/lists-dropdownWill do so when I get homeI don't know where that could come from. Can you push the current version of your code (to a separate branch) so that I can try to debug it? The code kinda works because it doesn't drag the whole block with no escape anymore, but i still get:Uncaught TypeError: option is undefined
- Maximouse
-
1000+ posts
How to make number dropdowns functional?
The “option is undefined” error is from the dropdown search addon. To fix it, change the line in addons/addons/editor-searchable-dropdowns/userscript.js that overrides Blockly.FieldDropdown.prototype.getOptions to assign the same function to Blockly.FieldTextDropdown.prototype.getOptions as well:
Blockly.FieldDropdown.prototype.getOptions = Blockly.FieldTextDropdown.prototype.getOptions = function () {
- AmpElectrecuted
-
1000+ posts
How to make number dropdowns functional?
(#12)this fixes the dropdown itself, but if you go to another tab or e.g. delete the list, this error occurs and everything in the palette before the “delete () of ()” block is gone:
The “option is undefined” error is from the dropdown search addon. To fix it, change the line in addons/addons/editor-searchable-dropdowns/userscript.js that overrides Blockly.FieldDropdown.prototype.getOptions to assign the same function to Blockly.FieldTextDropdown.prototype.getOptions as well:Blockly.FieldDropdown.prototype.getOptions = Blockly.FieldTextDropdown.prototype.getOptions = function () {
Uncaught TypeError: e.isOptionListDynamic is not a function
- Maximouse
-
1000+ posts
How to make number dropdowns functional?
Try adding this to field_textdropdown.js:Uncaught TypeError: e.isOptionListDynamic is not a function
/** * @return {boolean} True if the option list is generated by a function. */ Blockly.FieldTextDropdown.prototype.isOptionListDynamic = Blockly.FieldDropdown.prototype.isOptionListDynamic;
- AmpElectrecuted
-
1000+ posts
How to make number dropdowns functional?
(#14)yay this worksTry adding this to field_textdropdown.js:Uncaught TypeError: e.isOptionListDynamic is not a function/** * @return {boolean} True if the option list is generated by a function. */ Blockly.FieldTextDropdown.prototype.isOptionListDynamic = Blockly.FieldDropdown.prototype.isOptionListDynamic;
i've put credit in a code comment since this is just simple bugfixing, but if you want i can add a special thanks section to the credits page
- Discussion Forums
- » Advanced Topics
-
» How to make number dropdowns functional?