I was looking through the code for the Sprites tab and I noticed that when defining parameters for blocks, sometimes a percentage sign (%) is used, but other times a dollar sign ($) is used. I was just wondering why that is. Is there any difference between them? If so, what is it? I’ve just used the dollar sign for everything, so I was wonder if I’m doing something wrong.
Example of what I’m talking about:
Percent sign (%):
/**
* Sets the sprite velocity in pixel / sec
* @param vx
* @param vy
*/
//% group="Physics"
//% weight=100
//% blockId=spritesetvel block="set %sprite(mySprite) velocity to vx %vx vy %vy"
//% help=sprites/sprite/set-velocity
//% vx.shadow=spriteSpeedPicker
//% vy.shadow=spriteSpeedPicker
setVelocity(vx: number, vy: number): void {
this.vx = vx;
this.vy = vy;
}
Dollar sign ($):
/**
* Get the tile kind in a given direction if any
* @param direction
*/
//% blockId=spritetileat block="tile to $direction of $this(mySprite) is $tile"
//% tile.shadow=tileset_tile_picker
//% blockNamespace="scene" group="Locations" blockGap=8
//% help=scene/tile-kind-at
//% weight=20
tileKindAt(direction: TileDirection, tile: Image): boolean {
const tilemap = game.currentScene().tileMap;
let x = this.x >> tilemap.scale;
let y = this.y >> tilemap.scale;
switch (direction) {
case TileDirection.Top:
y = y - 1;
break;
case TileDirection.Bottom:
y = y + 1;
break;
case TileDirection.Left:
x = x - 1;
break;
case TileDirection.Right:
x = x + 1;
break;
case TileDirection.Center:
default:
break;
}
return tiles.getTileImage(tilemap.getTile(x, y)).equals(tile);
}
I’m also curious to know that this means:
%sprite(mySprite) or $this(mySprite)
Any help is appreciated.