My first time trying to make an extension

I made my first extension! It’s supposed to add one block that sets the background to a random color. The reason why I said its supposed to do that is because there is an error I can’t find and… I just suck at making stuff :frowning:

anyways here’s the extension!
YamJam-dev/background-extension: A MakeCode project

5 Likes

Think you can already do that with the block but hey! Great attempt!

2 Likes

I already knew that, I just wanted to try making an extension and I actually needed something for it to add, so I just did that :sweat_smile:

3 Likes

Hi! Looks like it’s broken because you need some single quotes around the groups array, and normal quotes around the name. It should be groups='["background color"]' instead of groups=['background color']
You can see an example of this being used in Explorer → mixer → ns.ts
You’ll also need to specify which group the block is in, so the whole thing should look like this:

//% color="#ADD8E6" weight=100 block="Background"
//% groups='["background color"]'
namespace BG {
    //% block
    //% group="background color"
    export function changeBG() {
        scene.setBackgroundColor(randint(1, 15))
    }
}

The thing is, it will only actually show the group name if there is more than 1 block defined. You also don’t need to specify the groups at the top in order to use them, you can just use the block specification, so what I would write is this:

//% color="#ADD8E6" weight=100 block="Background"
namespace BG {
    //% block
    //% group="background color"
    export function changeBG() {
        scene.setBackgroundColor(randint(1, 15))
    }

    //% block
    //% group="other group"
    export function otherBlockSoGroupsShowUp() {

    }
}

Which looks like this:

4 Likes

@WoofWoof I did what you said and it worked! Sort of… I also wanted to add another block so I did but it the first one doesn’t show up :frowning: I looked through my code dozens of times but it still doesn’t seem to work :frowning: :frowning: :frowning: :frowning: :frowning: :frowning: :sob:

3 Likes

Looks like you need to move your //% block and //% group=“screen split half” lines to be under the variable definitions. You can only turn functions into blocks, so those block definition lines can only work directly above a function definition.
Those variable definitions will still run just fine. They will always run at the start of the program like all other variable definitions.

1 Like

Im making 2 new blocks but 2 of the blocks stilllllllllllll don’t show up.

I added a block to use a sprite as the background and im trying to add another one where you can make a background animation but the animation block doesn’t show up, AS WELL as the split screen into halves.

ALSO I want to add an image editor to the sprite background block but instead I got the gallery list…

PLEASE HELP ME :sob: :sob: :sob: :sob: sob :sob: :sob: :sob: :sob: :cry:

the code for the half screen one is this:
BG.splitScreenHalf(color1, color2)

2 Likes

I can look at it later, but right now I can tell you that to make an image in the block it’s something like

//% block=“imageThingy $thing”
//% thing.shadow=screen_image_picker
function imageThingy(thing:Image) {}