A few block authoring questions

1: Is it possible to define a variadic function (a function you can call with any number of parameters)?

Essentially, I want the UI the array block provides (+ and - to add/remove slots) without requiring embedding an array parameter within my block.

2: When I do use an array as a stand-in for the above functionality, I notice that the default behavior is to create an array with two elements of the same value.

Similar to this code from @richard’s BlockObject extension, I’m doing

//% value.shadow="lists_create_with"
//% value.defl=<a reference to my own kind shadow block>

But the array starts out with two elements with the same value. Is there a way to influence what the array element values are when specifying lists_create_with and a custom defl shadow?

  1. We don’t currently support rest parameters, but it’s one of the things we have listed as ‘maybe someday, just not implemented yet’ on https://makecode.com/language (note there’s a minor typo → ‘reset’ operator)

  2. I don’t think we support this currently, though it seems like a good option; here’s where the default values for arrays is implemented for reference: https://github.com/microsoft/pxt/blob/f75076c74112cfe442ac0dfe0bca2dfecabd1fe3/pxtblocks/blocklyloader.ts#L166

1 Like