pxt-arcade
pxt-arcade copied to clipboard
Bug: Two Locations at the same TileMap coordinates on the same TileMap are not equal
When using tilemaps, MakeCode Arcade has blocks to retrieve an arbitrary tilemap location (tiles.getTileLocation(col,row)
) as well as the tilemap Location of a sprite (mySprite.tilemapLocation()
). Checking if two Locations are equal (i.e., they correspond to the same location on the TileMap) always returns false
.
To Reproduce Steps to reproduce the behavior:
- Create a new MakeCode Arcade project.
- Add a Tilemap asset.
- Compare tilemap locations. Code:
tiles.setCurrentTileMap(tilemap`level1`) // use whatever the your tilemap is called
// compare the same location
console.log(tiles.getTileLocation(0,0)==tiles.getTileLocation(0,0)) // false
// compare the location of a sprite at the same location
let mySprite = sprites.create(img`a a a`, SpriteKind.Player) // use whatever image
tiles.placeOnTile(mySprite, tiles.getTileLocation(3,4)) // place the sprite at (3,4) on the tilemap
console.log(mySprite.tilemapLocation()==tiles.getTileLocation(3,4)) // false
Expected behavior
- Tilemap locations at the same column and row should return true when compared.
- And/or in Blocks mode, a warning or error should come up on the comparison block that Locations (or objects in general) can't be compared with it or the user should not be able to put a Location block into a logic block's open spaces.
Desktop (please complete the following information):
- OS: Windows 10 (build 19045)
- Browser: Chrome 129 (64-bit)
Additional context
I suppose this is because JavaScript comparisons using ==
of two objects are based on their references and not their values and two different Location objects would indeed not be the same. As a developer, this would be known, however for those just starting out, and considering that this comparison can be done in the Blocks editor as well, this could be confusing (sidenote: I ran into this issue while using MakeCode Arcade at a summer camp for youth 12-14).