Function Definition Connectable - setPreviousStatement (true)

31 views
Skip to first unread message

Maciek Kociela

unread,
Apr 24, 2021, 8:17:53 AM4/24/21
to Blockly
Hey,

Firstly I would like to thank all Blockly Team for building such an AMAZING tool and Blockly community for all your help!

My program gets a little bit bigger so now I work on setting up the workflow.

I found out that collapsing/expanding blocks works great for that purpose, but there is still a problem with function definitions. (*described on a photo)

Do you know if there is a way to make functions connectable?

For example something like that:
Blockly.Blocks.procedures_defnoreturn.setPreviousStatement(true, null);
Blockly.Blocks.procedures_defnoreturn.setNextStatement(true, null);

Thanks,
Maciej

blockly.png

Beka Westberg

unread,
Apr 24, 2021, 5:48:31 PM4/24/21
to blo...@googlegroups.com
Hello,

setPreviousStatement and setNextStatement are definitely what you're looking for =) But they need to be called on an instance of a block, not on its definition. So basically, they need to be called from the block's init() method.

Sadly, I think that the only way to do that at the moment is to copy the procedure block definitions, and add the calls yourself. This will require a bit more maintenance, because if bugs are ever discovered and fixed in the procedure blocks you'll need to add them manually. But it should give you the behavior that you want =)

I hope that helps! If you have any further questions please reply!
--Beka

--
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/48603a65-fdd0-4797-8f8e-6d909f7aaf65n%40googlegroups.com.

Maciek Kociela

unread,
Apr 25, 2021, 7:57:16 AM4/25/21
to Blockly
Hello Beka,

thank you for the help! I recorded a short video just to show you the next issue related to "setPreviousStatement and setNextStatement" inside of init of procedure.

Thanks,
Maciek

Beka Westberg

unread,
Apr 25, 2021, 4:45:48 PM4/25/21
to blo...@googlegroups.com
Hello Maciek,

Thank you for the video! That was really helpful :D

So it turns out that that's a bug in core D: If you look here there's a comment that says "Assume that a procedure definition is a top block". So if you have a procedure connected to the bottom of another block, it breaks. I'm going to put up a pull request in a bit to fix that, but if it gets merged it won't be available in a release until June :/ I'll send you a link to the PR once it's up so you can monkey-patch it if you want.

Also I wanted to point you toward this email thread which seems to want to do something similar to what you're doing. They ran into some problems with context menus and code generation that you might want to watch out for.

Best wishes,
Beka

Reply all
Reply to author
Forward
0 new messages