Re: Create custom function with mutator

50 views
Skip to first unread message

Beka Westberg

unread,
Apr 12, 2021, 6:15:00 PM4/12/21
to blo...@googlegroups.com
Hello,

You should be able to copy the procedure block definitions (and associated mutators), and then just add your setPreviousStatement and setNextStatement calls to the init function =)

Best,
Beka

On Mon, Apr 12, 2021 at 12:23 AM Naresh Chaudhari <chaudhary...@gmail.com> wrote:
Hi, How do i create custom function with mutator similar to "procedures_defnoreturn" but my custom function should have 
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);

--
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+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/5a05ee01-95aa-40be-bc45-ad01fa1771den%40googlegroups.com.

Naresh Chaudhari

unread,
Apr 14, 2021, 4:47:08 AM4/14/21
to Blockly
Thanks Beka, I did the same but currently I'm facing a problem is... 

Capture1.PNG
Here in the screenshot you can see.... I have created class block and define block. ( Copied the code from  procedure block definitions (and associated mutators), and then just add your setPreviousStatement and setNextStatement to these blocks and remained the labels   )

But now i have added define block inside class block so corresponding code should be generate inside class block right? Why the code is generating outside of the class block? Any ideas? 

Naresh Chaudhari

unread,
Apr 14, 2021, 5:12:50 AM4/14/21
to Blockly
Also in small videos atteched below...
 
If I want to create calling function using write click on the block and "Create unnamed" option it is creating method plus function name. but I need only function name. if the block is not having parent block then it is working fine. so do I fixed the issue if the block is having parent block and want to create only function name?
screencast-nimbus-capture-2021.04.14-14_31_57.webm

Beka Westberg

unread,
Apr 14, 2021, 6:01:51 PM4/14/21
to blo...@googlegroups.com
Hello,

> I have added define block inside class block so corresponding code should be generate inside class block right?

Sadly no, it's not quite that simple :/ Blockly implements something called "function hoisting" where all of the function definitions are defined (in the generated code-string) before any of the "driver code".

If you look at the procedure block-code generator definitions you can see that the procedures_defreturn block doesn't return a code string. Instead it returns `null` which indicates to the python language generator that it handled its code generation separately, in this case by appending to the `Blockly.Python.definitions_` map.

If you want your definition to be generated inside of the class block, you'll want to modify the block-code generator definition you're using so that it returns a code string, instead of appending to the `definitions_` map =)

> If I want to create calling function using write click on the block and "Create unnamed" option it is creating method plus function name. but I need only function name. if the block is not having parent block then it is working fine. so do I fixed the issue if the block is having parent block and want to create only function name?

It sounds like the custom context menu isn't working properly with your new block. You'll probably want to start looking around where the calltype option is defined. Without more info I can't give a more specific recommendation :/ But with a bit of a debugging it should be pretty easy to figure out!

Best of luck,
Beka

Reply all
Reply to author
Forward
0 new messages