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 
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 
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:
5 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
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:
1 Like
welp, there goes any hope in that happening 
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.
@YamJamTheGoober 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.