How to change the argument block for functions

122 views
Skip to first unread message

Vivek

unread,
May 24, 2018, 5:59:17 AM5/24/18
to Blockly
Hello team

I am using procedure.js files for function generation. I want to do some changes in argument blocks which open as pop up in procedures. As described in image attached above:-
I want to add a dropdown field in the argument block on the basis of value of dropdown the name variable should be changed before the variable gets created.



Regards 
vivek
Untitled.png

Andrew n marshall

unread,
May 24, 2018, 4:43:41 PM5/24/18
to blo...@googlegroups.com
I'm not clear about what you are aiming for with the dropdown, but the procedures_mutatorarg is the block used as the mutator's argument block, found in the procedures.js file.

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vivek

unread,
May 28, 2018, 3:07:18 AM5/28/18
to Blockly
Hi Andrew,

I am trying to create a function block in which, I can add arguments of different types like int,char,float,etc.
These data types should be displayed in dropdown of the block and when I select the value from dropdown then on basis of that selection of dropdown value it should create the variable after giving the name also. You can look at the snapshot below:-



Hope now it will be cleared to you what I want to achieve.
Thank You 
Vivek
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.

Andrew n marshall

unread,
May 29, 2018, 1:46:50 PM5/29/18
to blo...@googlegroups.com
Something like this should be possible, and the blocks/procedures,js and core/procedures.js files are the place to start. Be aware that all variables in blockly, including the user-function arguments, are global variables. You'll want to look at how user-functions definitions interact with the workspace's VariableMap. The createVariable() method does allow you to attach an optional type string to the block, which may help you.

That said, that may force you to use typed variables everywhere, replacing use of blocks/variables.js with blocks/variables_dynamic.js. This is an in-development feature that requires a little extra work to support the toolbox.  I suggest looking at the "Categories (type variables)" toolbox in the playground. For those tests, each variable type has a separate "Create variable" button.

Looking at that, you may want to consider a function mutator toolbox with separate argument blocks for each allow variable type, instead of drop downs on each block. These might be color coded to match "Math" (number), "Logic" (boolean), "Text" (string) blocks.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages