Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Problems with Create Dynamic Dropdown Toolbox

58 views
Skip to first unread message
Message has been deleted

New blockly user

unread,
Apr 29, 2025, 11:50:52 AMApr 29
to Blockly
I recently tried to make an OOP solution for a method block and I got a mutator with a field array this.params. Tell me what I can do with a drop-down toolbox with parameters created in this way. I just haven't been able to implement it myself or with GPT yet. Please tell me which way to look. I new in Blockly but in need me Code:Blockly.common.defineBlocks({
param_block: {
init() {
this.appendDummyInput()
.appendField('Параметр:')
.appendField(new Blockly.FieldTextInput('x'), 'name')
.appendField('тип')
.appendField(new Blockly.FieldDropdown([
['int', 'int'],
['str', 'str'],
['bool', 'bool']
]), 'type');
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(230);
}
}
});

// param_container
Blockly.common.defineBlocks({
param_container: {
init: function () {
this.appendDummyInput()
.appendField('Параметры');
this.setNextStatement(true, null);
this.setColour(260);
this.setTooltip('Контейнер для параметров метода');
}
}
});

const method = {
init: function () {
this.params = [];
this.appendDummyInput('NAME')
.appendField('method')
.appendField(new Blockly.FieldTextInput('methodname'), 'NAME')


this.appendStatementInput('Code').appendField('Code');
this.appendValueInput('Return').appendField('Return');
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip('Метод класса с параметрами');
this.setHelpUrl('');
this.setMutator(new Blockly.icons.MutatorIcon(['param_block'], this));
},
And any code...

epas...@google.com

unread,
Apr 29, 2025, 12:58:20 PMApr 29
to Blockly
Hi there,

I'm not sure I understand what you're trying to build. Can you describe a bit more what you're trying to make? Or is there something similar you can point us at or a drawing of what you're thinking of?

Cheers,
Erik

New blockly user

unread,
Apr 29, 2025, 1:47:31 PMApr 29
to Blockly
Update: I apologize in advance, there should have been a line break and a period between me and Code, but I missed it. Thanks in advance.

вторник, 29 апреля 2025 г. в 20:50:52 UTC+5, New blockly user:

New blockly user

unread,
Apr 30, 2025, 11:47:44 AMApr 30
to Blockly

hi I have a parameter creation and I want to dynamically create such local toolboxes for these parameters PS second screen from scratch. And there when manipulating with functions you can get special places blocks parameters. Was I able to clarify?
Безымянный.png
вторник, 29 апреля 2025 г. в 21:58:20 UTC+5, epas...@google.com:

Erik Pasternak

unread,
Apr 30, 2025, 12:34:55 PMApr 30
to blo...@googlegroups.com
Ah, Scratch wrote a fair amount of custom blocks to make that work. If I recall correctly, the blocks you can drag out are defined as shadow blocks with special handling for drag events that creates a copy of the block. I don't know all the details, but I can point you at some of the code they used to make this.
Unfortunately, there's no simple way to add that behavior, so this may require a more advanced understanding of Blockly and some time working through how Scratch implemented it.
Erik Pasternak | Unblocker | epas...@google.com     


--
You received this message because you are subscribed to a topic in the Google Groups "Blockly" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/blockly/uBLqFVpFQmg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to blockly+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/blockly/0ab84cb6-7bff-45cb-8187-3fc754ec3110n%40googlegroups.com.

Aaron Dodson

unread,
Apr 30, 2025, 12:39:28 PMApr 30
to Blockly
See also https://github.com/gonfunko/scratch-blocks/pull/119/files for how this can be done in modern Blockly (and https://github.com/gonfunko/scratch-blocks/pull/217/files, which prevents the dragged-out argument blocks from themselves becoming sources of infinite copies of themselves on drag)

New blockly user

unread,
Apr 30, 2025, 2:29:25 PMApr 30
to Blockly
THX all 
среда, 30 апреля 2025 г. в 21:39:28 UTC+5, ado...@google.com:
Reply all
Reply to author
Forward
0 new messages