Help for making "select tile" block for extension

@Richard I’m working on my “1x1 mini-tilemap” extension, but I can’t figure out how to make a clickable selector for selecting a tile. I am making it so there is a block that says “Generate mini tilemap on all $selected tiles with collision $collisionImg”, but when I export the function, I’d like to have it be where
"export function GenerateCollision(selected: Tile, collisionImg: Image) {... "
would work, but I don’t know the names of these, and using “any” as the type makes it crash (and I’d also like to know how to have the “shadow variables” work, so it already has something in the block when it is dragged out.) I looked for documentation on this topic, but found none besides a few templates (that don’t help at all) in the “extension playground”. Thanks in advance for any help! There’s a copy of the extension that I’m working on if you import “Kiwiphoenix364/physics-3” when you create a new project.

1 Like

@Kiwiphoenix364 I’m not sure I have a clear idea of what you’re going for. Could you give me a picture of what you want the block to look like? a drawing is fine

2 Likes

Sorry for being unclear, but I’d like this to work (and not crash), and also for the block to be like this from the start, instead of manually having to drag in an image and a block for the type. I already have code (that works when it’s not an extension), but I’d like for it to be an extension.
image

1 Like

Ah, that’s easy!

//% block="generate mini tilemap on all $selected tiles with collision $collisionImg"
//% selected.shadow=tileset_tile_picker
//% collisionImg.shadow=screen_image_picker
export function GenerateCollision(selected: Tile, collisionImg: Image) {
}

The important things to note here:

  1. Make sure all mentions of the argument name (e.g. “selected”) match the name in the actual function
  2. The “shadow” of the block takes a blockId of another block. In this case, both shadows come from this file: https://github.com/microsoft/pxt-common-packages/blob/master/libs/screen/fieldeditors.ts
3 Likes

So, later after this

export function GenerateCollision(selected: Tile, collisionImg: Image) {
}

I have

for (let value2 of tiles.getTilesByType(selected)) {
}

So, for “export function GenerateCollision(selected: HERE” What should I put where the “HERE” is, because Tile doesn’t work after “selected:”, and if I put “any”, it makes the extension crash. TO BE CLEAR I am trying to have the block input a tile, then have the code use it by finding an array of all the tiles of the type that are selected. You can look at the function in this code (this is in blocks) to see how I intend the block to be (like the function, but as the extension).

oh, it should be Image

1 Like