@foxrii you can change the palette by going to the assets tab of the editor (next to blocks and javascript).
there’s a button for it on the left-hand side
@foxrii you can change the palette by going to the assets tab of the editor (next to blocks and javascript).
there’s a button for it on the left-hand side
@richard… Xd i wanted to make a extension for fun yesterday but i wanted to add a single namespace but with like… ill just show you
stuff like that
@YuHayate use the //% subcategory=whatever
annotation on your functions. It works just like the group
annotation but puts the blocks into a subcategory instead.
You can also rearrange the order of subcategories with an annotation on the namespace like this:
//% subcategories='["number", "boolean", "string"]'
alright thx
what about default values on blocks like this?
like i want there to be a option to if you want to give that test a id or not
the block only work when i have it like this
i tryed to make it like in js but that does not work ether
//% block="foo || $a"
export function foo(a: string = "default") {
// insert code here
}
//% a.defl="whatever"
hmm
i may have found why, still confused tho
ah, right. i forgot we don’t support default values for string parameters. also, any parameter after the ||
in a block definition needs to be optional.
/**
* This is a good example. We can't specify the default value of
* the string in the function definition but we can use an if
* statement to set it ourselves
*/
//% block="good example || $id"
//% id.defl="default"
function goodExample(id?: string) {
if (!id) id = "default";
}
/**
* The examples below are both invalid. The first one won't
* compile correctly from blocks to typescript and the second
* one won't compile at all
*/
//% block="bad example || $id"
//% id.defl="default"
function badExample(id: string) {
}
//% block="bad example || $id"
//% id.defl="default"
function anotherBadExample(id = "default") {
}
@richard . a bug?
any ideas what causes it?
@YuHayate when that happens, it almost always means you messed up one of your block definitions. In this case, looks like you misspelled the shadow block id for one of your functions:
Xd, thx, i didnt even know that is sent errors to the console
hey @richard, I’m always asking you for help it seems, ig I’m not good at finding information myself loI
anyways, how would i make a block that is like an if statement? or a for loop
like shown bellow
is this possible to do in an extension?
making a block like an if-statement is not possible. blocks made by extensions can have at most one statement input (one “mouth”)
making a block like a for-loop is totally possible though! here’s one for example:
//% weight=100 color=#0fbc11 icon=""
namespace custom {
//% blockId=my_custom_for_loop
//% block="for $index from 0 to $upperBound"
//% draggableParameters=reporter
//% upperBound.defl=4
//% handlerStatement=true
export function forLoop(upperBound: number, handler: (index: number) => void) {
for (let i = 0; i <= upperBound; i++) {
handler(i);
}
}
}
and here’s the block that produces:
also, no worries! i’m always happy to answer questions when i can
what about two handlers?
is that posible?
@YuHayate nope! one handler max
ok : (
hey @richard just wanted to know what im doing wrong here.
function play8BitSound() {
let effects: number[][] = [[440, 0, 4550], [330, 0, 100]...];
for (let i = 0; i < effects.length; i++) {
let effect = effects[i];
music.play(music.createSoundEffect(
WaveShape.Square,
effect[0], // startHz
effect[0], // endHz (same as startHz)
effect[1], // startVolume
effect[1], // endVolume (same as startVolume)
effect[2], // duration
SoundExpressionEffect.None,
InterpolationCurve.Linear
), music.PlaybackMode.UntilDone);
}
}