# Get number of columns and rows in tilemap

**URL:** https://forum.makecode.com/t/get-number-of-columns-and-rows-in-tilemap/3752
**Category:** Help
**Created:** [October 3, 2020, 10:52am UTC](https://forum.makecode.com/t/get-number-of-columns-and-rows-in-tilemap/3752 "2020-10-03T10:52:10Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![cosmoscowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cosmoscowboy/32/1718_2.png) [@cosmoscowboy](https://forum.makecode.com/u/cosmoscowboy)
#### Post date: [October 3, 2020, 10:52am UTC](https://forum.makecode.com/t/get-number-of-columns-and-rows-in-tilemap/3752/1 "2020-10-03T10:52:10Z")

</div>

Based on this question,

> [@Trying to find width of tilemap level](https://forum.makecode.com/t/trying-to-find-width-of-tilemap-level/1134/2):
>
> @p3nguinc4g3 How dit you set the tileMapData into a variable? I am also curious to find out what the width and height is. There is a function, TileMapData.isOutsideMap(x, y), but I am not sure how to use it. Instead of defining a tile as the random location the sprite starts at, I want to place the sprite at the bottom and middle of the tilemap. Maybe the width and height of a tilemap works differently than the location of a tile. Maybe if you repost this issue under Arcade | Help, someone els…

I can make a tilemap to be a certain number of columns and rows, but once it’s made, I cannot see a block function to get those values. I have to remember what those values are for each tilemap and then find a location at col/row coordinates.

Knowing the number of columns and rows in block code, I could then place sprites within the timemap (bottom of tile map in the middle) such as

place [sprite] on top of (tilemap col( (_tilemap.columns % 2_ )) row (_tilemap.rows - 1_))

---

<div class="post-metadata">

### Author: ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)
#### Post date: [October 3, 2020, 11:29am UTC](https://forum.makecode.com/t/get-number-of-columns-and-rows-in-tilemap/3752/2 "2020-10-03T11:29:51Z")

</div>

Are you talking about placing a Sprite onto one of those (col, row) coordinates?

---

<div class="post-metadata">

### Author: ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)
#### Post date: [October 3, 2020, 11:32am UTC](https://forum.makecode.com/t/get-number-of-columns-and-rows-in-tilemap/3752/3 "2020-10-03T11:32:12Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/4/491ba53fe5374c20169c3ded0c972951c32486da.png)  
This is the tilemap row and column where you can edit the space on how big you want the tilemap to be.

---

<div class="post-metadata">

### Author: ![cosmoscowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cosmoscowboy/32/1718_2.png) [@cosmoscowboy](https://forum.makecode.com/u/cosmoscowboy)
#### Post date: [October 3, 2020, 11:51am UTC](https://forum.makecode.com/t/get-number-of-columns-and-rows-in-tilemap/3752/4 "2020-10-03T11:51:14Z")

</div>

Exactly. I need to remember those values for each tilemap I make, and maybe even store that in a variable. I want to be able to call block code to get those values, so that if I change the tilemap, the, code such as:

let centerX = tilemap.width / 2  
let centerY = tilemap.height / 2

Still works.

---

<div class="post-metadata">

### Author: ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)
#### Post date: [October 3, 2020, 11:53am UTC](https://forum.makecode.com/t/get-number-of-columns-and-rows-in-tilemap/3752/5 "2020-10-03T11:53:07Z")

</div>

So you want to turn this as a function and still call those numbers?

---

<div class="post-metadata">

### Author: ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)
#### Post date: [October 3, 2020, 11:55am UTC](https://forum.makecode.com/t/get-number-of-columns-and-rows-in-tilemap/3752/6 "2020-10-03T11:55:57Z")

</div>

You know like this?

 ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/f/fb10722b3d57b1bce18b34a32dbf88b4e47e844e.png)  
You can always change the numbers on the function so you don’t have to remember as much number I think

---

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [October 3, 2020, 2:44pm UTC](https://forum.makecode.com/t/get-number-of-columns-and-rows-in-tilemap/3752/7 "2020-10-03T14:44:57Z")

</div>

I think @cosmoscowboy wants to be able to get the width and height from his code, and not need to hard code the tilemap with and height in his code

---

<div class="post-metadata">

### Author: ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)
#### Post date: [October 3, 2020, 2:45pm UTC](https://forum.makecode.com/t/get-number-of-columns-and-rows-in-tilemap/3752/8 "2020-10-03T14:45:22Z")

</div>

oh. I was just trying to help

---

<div class="post-metadata">

### Author: ![cosmoscowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cosmoscowboy/32/1718_2.png) [@cosmoscowboy](https://forum.makecode.com/u/cosmoscowboy)
#### Post date: [October 3, 2020, 2:45pm UTC](https://forum.makecode.com/t/get-number-of-columns-and-rows-in-tilemap/3752/9 "2020-10-03T14:45:55Z")

</div>

I like your idea of creating the function, but it is just the same as having called the original code of ‘place sprite on top of…’.

I am just curious to know if you can get the width/height of a tilemap in order to make decisions in code based on those values. Thanks for your help.

---

<div class="post-metadata">

### Author: ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)
#### Post date: [October 4, 2020, 10:21pm UTC](https://forum.makecode.com/t/get-number-of-columns-and-rows-in-tilemap/3752/10 "2020-10-04T22:21:02Z")

</div>

You’ll want to use the tilemaps extension for that:

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/8/8dce14d70cd26623b4bc40ffe6639a3691bd0ca8.png)

Under the location group:

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/a/a1b4291bf37994aa9777c818fe188f3b51a70fed.png)

---

<div class="post-metadata">

### Author: ![cosmoscowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cosmoscowboy/32/1718_2.png) [@cosmoscowboy](https://forum.makecode.com/u/cosmoscowboy)
#### Post date: [October 5, 2020, 12:30am UTC](https://forum.makecode.com/t/get-number-of-columns-and-rows-in-tilemap/3752/11 "2020-10-05T00:30:16Z")

</div>

@jwunderl Thanks, I indeed came across that extension, it is very helpful.
