Making my own block that has a body and is not a top block

Also, I should mention, generally it’s best to do APIs that take in non-primitives inside of libs/ instead of in the simulator. Then you don’t have to deal with internals directly like this. For example, you could have an API in the simulator like this:

//%
export function addBlock(block: string) {
    board().addBlock(block)
}

and then define the public function in the libs folder like this:

//% blockId=subtract_shapes block="subtract shapes" 
//% topblock=false
//% handlerStatement=true
export function subtractShapes(body: () => void): void {
    internalNamespace.addBlock("difference( <CHILDREN> )")
    body()
}

If you start the name of the internal function with an underscore (e.g. _addBlock) then it won’t show up to the user in completions.

1 Like