Discuss Scratch

AmpElectrecuted
Scratcher
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
Scratcher
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
Scratcher
1000+ posts

How to make number dropdowns functional?

Pufferfish_Test wrote:

(#2)
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
it is a shadow, the whole block is dragged. my numberdropdown file is the same as vanilla
Maximouse
Scratcher
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:
Blockly.FieldTextDropdown.prototype.getOptions_ = Blockly.FieldDropdown.prototype.getOptions_;
to:
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
Scratcher
1000+ posts

How to make number dropdowns functional?

Maximouse wrote:

(#4)
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-
Doesn't seem to work. the blocks just disappear when i create a variable. Requiring utils and using it doesn't help either
Maximouse
Scratcher
1000+ posts

How to make number dropdowns functional?

AmpElectrecuted wrote:

Maximouse wrote:

(#4)
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-
Doesn't seem to work. the blocks just disappear when i create a variable. Requiring utils and using it doesn't help either
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?
AmpElectrecuted
Scratcher
1000+ posts

How to make number dropdowns functional?

Maximouse wrote:

(#6)
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?
yeah
just let me boot up my webpack server quickly
AmpElectrecuted
Scratcher
1000+ posts

How to make number dropdowns functional?

AmpElectrecuted wrote:

(#7)

Maximouse wrote:

(#6)
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?
yeah
just let me boot up my webpack server quickly
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

Last edited by AmpElectrecuted (March 12, 2025 07:53:02)

Maximouse
Scratcher
1000+ posts

How to make number dropdowns functional?

AmpElectrecuted wrote:

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
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?
AmpElectrecuted
Scratcher
1000+ posts

How to make number dropdowns functional?

Maximouse wrote:

AmpElectrecuted wrote:

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
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?
Will do so when I get home
AmpElectrecuted
Scratcher
1000+ posts

How to make number dropdowns functional?

AmpElectrecuted wrote:

(#10)

Maximouse wrote:

AmpElectrecuted wrote:

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
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?
Will do so when I get home
https://codeberg.org/AmpMod/scratch-blocks/src/branch/lists-dropdown
Maximouse
Scratcher
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
Scratcher
1000+ posts

How to make number dropdowns functional?

Maximouse wrote:

(#12)
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 () {
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:
Uncaught TypeError: e.isOptionListDynamic is not a function
Maximouse
Scratcher
1000+ posts

How to make number dropdowns functional?

AmpElectrecuted wrote:

Uncaught TypeError: e.isOptionListDynamic is not a function
Try adding this to field_textdropdown.js:
/**
 * @return {boolean} True if the option list is generated by a function.
 */
Blockly.FieldTextDropdown.prototype.isOptionListDynamic = Blockly.FieldDropdown.prototype.isOptionListDynamic;
AmpElectrecuted
Scratcher
1000+ posts

How to make number dropdowns functional?

Maximouse wrote:

(#14)

AmpElectrecuted wrote:

Uncaught TypeError: e.isOptionListDynamic is not a function
Try adding this to field_textdropdown.js:
/**
 * @return {boolean} True if the option list is generated by a function.
 */
Blockly.FieldTextDropdown.prototype.isOptionListDynamic = Blockly.FieldDropdown.prototype.isOptionListDynamic;
yay this works

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

Powered by DjangoBB