"Create Block" Block

I have done it. A block that allows you to create custom blocks.

image
Credits: Thanks to wunder_wulfe for creating this block:
image
and the js for this script
image
(the [scratchblocks] (name) [/scratchblocks] part was me)
(thanks to @ego-lay_atman-bay for telling me this)

project

Snap! 7.2.1 - Build Your Own Blocks

source
xml

<blocks app="Snap! 7, https://snap.berkeley.edu" version="2"><palette><category name="Developer Version" color="150,150,150,1"/></palette><block-definition s="create block name %&apos;name&apos; category %&apos;category&apos; type %&apos;type&apos; code %&apos;typecode&apos; %&apos;code&apos;" type="command" category="Developer Version"><comment w="161" collapsed="false">Created by Mr_OwlsssSnap&#xD;----------------------------------------------------&#xD;Creates a block with the code you give it. It has two options: XML or blocks. If you are using blocks, make sure to put in a ring. &#xD;Requires JS.</comment><variables><list struct="atomic" id="3">xml,block xml</list></variables><header></header><code></code><translations></translations><inputs><input type="%s"></input><input type="%s">other<options>motion&#xD;looks&#xD;sound&#xD;pen&#xD;control&#xD;sensing&#xD;operators&#xD;variables&#xD;other</options></input><input type="%s" readonly="true">command<options>command&#xD;booleen&#xD;reporter</options></input><input type="%s">blocks<options>blocks&#xD;xml</options></input><input type="%txt"></input></inputs><script><custom-block s="Created by Mr_OwlsssSnap"></custom-block><block s="doIfElse"><custom-block s="JavaScript enabled?"></custom-block><script><block s="doIfElse"><block s="reportEquals"><block var="typecode"/><l>blocks</l></block><script><block s="doSetVar"><l>block xml</l><custom-block s="Script : Export %cmdRing"><block var="code"/></custom-block></block><block s="doRun"><block s="reportJSFunction"><list><l>xmlString</l><l>silent</l></list><block s="reportJoinWords"><list><l>this.parentThatIsA(IDE_Morph).rawOpenBlocksString(xmlString, "</l><block var="name"/><l>", true)</l></list></block></block><list><block s="reportJoinWords"><list><l>&lt;blocks app="Snap! 7, https://snap.berkeley.edu" version="2"&gt;&lt;block-definition s="</l><block var="name"/><l>" type="</l><block var="type"/><l>" category="</l><block var="category"/><l>"&gt;&lt;header&gt;&lt;/header&gt;&lt;code&gt;&lt;/code&gt;&lt;translations&gt;&lt;/translations&gt;&lt;inputs&gt;&lt;/inputs&gt;</l><block var="block xml"/><l>&lt;/block-definition&gt;&lt;/blocks&gt;</l></list></block><l></l><l></l></list></block></script><script><block s="doRun"><block s="reportJSFunction"><list><l>xmlString</l><l>silent</l></list><block s="reportJoinWords"><list><l>this.parentThatIsA(IDE_Morph).rawOpenBlocksString(xmlString, "</l><block var="name"/><l>", true)</l></list></block></block><list><block s="reportJoinWords"><list><l>&lt;blocks app="Snap! 7, https://snap.berkeley.edu" version="2"&gt;&lt;block-definition s="</l><block var="name"/><l>" type="</l><block var="type"/><l>" category="</l><block var="category"/><l>"&gt;&lt;header&gt;&lt;/header&gt;&lt;code&gt;&lt;/code&gt;&lt;translations&gt;&lt;/translations&gt;&lt;inputs&gt;&lt;/inputs&gt;</l><block var="code"/><l>&lt;/block-definition&gt;&lt;/blocks&gt;</l></list></block><l></l><l></l></list></block></script></block></script><script><block s="doApplyExtension"><l>err_error(msg)</l><list><l>You need to enable JavaScript in order for this block to run.</l></list></block></script></block><custom-block s="Created by Mr_OwlsssSnap"></custom-block></script></block-definition><block-definition s="JavaScript enabled?" type="predicate" category="sensing"><comment x="0" y="0" w="90" collapsed="false">Tells you if JavaScript is enabled with no error if it is not.</comment><header></header><code></code><translations></translations><inputs></inputs><script><block s="doDeclareVariables"><list><l>a</l></list></block><block s="doSetVar"><l>a</l><block s="reportBoolean"><l><bool>false</bool></l></block></block><custom-block s="safely try %cs then if %upvar %cs"><script><block s="doSetVar"><l>a</l><block s="evaluate"><block s="reportJSFunction"><list></list><l>return true;</l></block><list></list></block></block></script><l>error</l><script><block s="doIf"><block s="reportEquals"><block var="error"/><l>JavaScript extensions for Snap! are off</l></block><script><block s="doSetVar"><l>a</l><block s="reportBoolean"><l><bool>false</bool></l></block></block></script></block></script></custom-block><block s="doReport"><block var="a"/></block></script><scripts><script x="167" y="95.46666666666664"><block s="fork"><block s="reifyScript"><script><block s="doWarp"><script></script></block></script><list></list></block><list></list></block></script><script x="316" y="201.80000000000007"><block s="doDeclareVariables"><list><l>a</l></list></block><block s="doSetVar"><l>a</l><block s="reportBoolean"><l><bool>false</bool></l></block></block><block s="fork"><block s="reifyScript"><script><block s="doWarp"><script><block s="doSetVar"><l>a</l><block s="evaluate"><block s="reportJSFunction"><list></list><l>return true;</l></block><list></list></block></block></script></block></script><list></list></block><list></list></block><block s="doRepeat"><l>1</l><script><block s="doWait"><l>0</l></block></script></block><block s="doReport"><block var="a"/></block></script></scripts></block-definition><block-definition s="safely try %&apos;action&apos; then if %&apos;error&apos; %&apos;handler&apos;" type="command" category="control"><comment x="0" y="0" w="276" collapsed="false">Catch errors.&#xD;&#xD;Runs the first script. If it succeeds, nothing else happens.&#xD;But if it has an error (something that would otherwise result&#xD;in a red halo around the block), then the second script is run,&#xD;with the text of the error message that would have been shown in the variable ERROR.</comment><header></header><code></code><translations>pt:tenta executar _ e, em caso de erro _ , executa _&#xD;ca:prova de forma segura _ i si _ _&#xD;</translations><inputs><input type="%cs"></input><input type="%upvar"></input><input type="%cs"></input></inputs><script><block s="doApplyExtension"><l>err_try(cmd, catch, err)</l><list><block var="action"/><block var="handler"/><block var="error"/></list></block><block s="doApplyExtension"><l>err_reset</l><list></list></block></script></block-definition><block-definition s="Script : Export %&apos;script&apos;" type="reporter" category="control"><header></header><code></code><translations></translations><inputs><input type="%cmdRing"></input></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>script</l></list><l>var ide = this.parentThatIsA(IDE_Morph),&#xD; blockEditor = this.parentThatIsA(BlockEditorMorph);&#xD;if (!ide &amp;&amp; blockEditor) {&#xD; ide = blockEditor.target.parentThatIsA(IDE_Morph);&#xD;}&#xD;if (ide) {&#xD; return ide.serializer.serialize( script.expression);&#xD;}</l></block><list><block var="script"/></list></block></block></script></block-definition><block-definition s="Created by Mr_OwlsssSnap" type="command" category="other" helper="true"><header></header><code></code><translations></translations><inputs></inputs></block-definition></blocks>

blocks

Idk what you would use this for, but here ya go.


(C) 2022 Mr_OwlsssSnap

I think I have seen this before. Didn’t BH make this on a project? Anyways, this is a pretty cool block.

No, I'm pretty sure he didn't, although I do know of an xml generator, which, to be honest, is a pretty cool project.

I've done a bit to make it smaller, here's my remix.

Cool!

Unrelated

It's not often you get THIS error message on an official OS:

(Yes that is my computer)

Which one?

Yes, for Snap!Con last year. It was pretty flaky though. I would definitely use Jens's new metaprogramming features to rewrite it.

Windows

Which version?

3.1 lol

I found two small errors, in the pulldown menus. One is that you left out the Lists category. (And really you should also have any custom categories that libraries have made!) The other is that hexagonal blocks are Predicates (i.e., functions), not Booleans (just the two values True and False).

But I would be afraid to run anything that uses a JOIN of a million inputs as input to JS Function, for fear of code injection by malicious users. I'm waiting until there's a bulletproof version!

Maybe it was helicoptur then.

Edit: maybe both

How old is that device?

Hmm, I've tried
untitled script pic - 2022-02-22T022923.157
but no luck. Is there a legit way to create or modify definition of custom block?

Not yet. Jens tells me there are technical issues in the way. But it's the obvious next step down this road...

Well, it's running on a Wii...

image

In my remix, I've fixed both of those.

Cool !

Can you make somes examples in your project for for those who don't understand how it works...

To improve it, it will be easy to put all the xml code in the slot (not just the script part)

Do you mean, i.e., putting the XML of a block into the code input?

all this: (when we export a block)
image
not only this part:
image