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) {}

By the way, the background is finished(kinda), but does anyone know why the array doesn’t show up in the new animation background block thingymajig? Here’s what I did:

export function backgroundAnimation(frames: Image, interval: number, scale: number) {
backgroundAnim = sprites.create(frames[1], SpriteKind.backAnim)
backgroundAnim.z = 1 / 0 * -1
backgroundAnim.setFlag(SpriteFlag.RelativeToCamera, true)
backgroundAnim.scale = scale
backgroundAnim.setPosition(scene.cameraProperty(CameraProperty.X), scene.cameraProperty(CameraProperty.Y))
animation.runImageAnimation(
backgroundAnim,
frames,
interval,
true

1 Like

Yeah I’m calling the bird himself
@richard, why doesn’t the array show up in the background animation block?


as you can see, my block doesn’t have any array in it, even thought I wrote this:
image

1 Like

welp, there goes any hope in that happening :frowning:

Oh and I added a sprite editor to the sprite background block, here ya go!

anyways, heres another update: YamJam-dev/pxt-background-extension: A simple and unperfected extension that adds a couple blocks to spice up the background of your game.

@YamJam you need to set the shadow block for array arguments.

if you want an array to appear, it would look like this:

//% frames.shadow=lists_create_with

if you wanted the animation block to appear, you would use the block id of that function like so:

//% frames.shadow=animation_editor 
2 Likes

It’s always the shadow thing! Thanks @richard, I’ll try it.