# RMMV[SOLVED] How to count the number of region ?

Status
Not open for further replies.

#### Furia25

##### Villager
Hello, this is my first thread. (I am on mv)
Sorry for my potentially bad english, this is not my first language.

It's a very precise question, i'd like to count how many of specific region are in a map in a script.
Pictures are better than words.

For example the script/function will return 38 tiles,
Sorry, I can't express myself well, thank you in advance for your help.
PS : I looked in rpg_object.js, but nothing that tells me how...

Last edited:

#### caethyril

##### ^_^
You will need to loop through all tiles on the map and check the region ID of each one, e.g.
JavaScript:
``var n = 0; for (var x = \$gameMap.width(); x--;) for (var y = \$gameMap.height(); y--;) if (\$gameMap.regionId(x, y) === 111) n++; n``
This is written for use in an eval, e.g. Control Variables -> Script. Explanation:
• `var n = 0;` => initialise tile counter
• `for (var x = \$gameMap.width(); x--;)` => loop through all `x` values
`for (var y = \$gameMap.height(); y--;)` => loop through all `y` values
• `if (\$gameMap.regionId(x, y) === 111) n++;` => +1 to counter if the region is `111`
• `n` => return the value of the counter
Details on the `for` loop in JavaScript:

#### Furia25

##### Villager
You will need to loop through all tiles on the map and check the region ID of each one, e.g.
JavaScript:
``var n = 0; for (var x = \$gameMap.width(); x--;) for (var y = \$gameMap.height(); y--;) if (\$gameMap.regionId(x, y) === 111) n++; n``
This is written for use in an eval, e.g. Control Variables -> Script. Explanation:
• `var n = 0;` => initialise tile counter
• `for (var x = \$gameMap.width(); x--;)` => loop through all `x` values
`for (var y = \$gameMap.height(); y--;)` => loop through all `y` values
• `if (\$gameMap.regionId(x, y) === 111) n++;` => +1 to counter if the region is `111`
• `n` => return the value of the counter
Details on the `for` loop in JavaScript:
Thank you very much I'll try this

#### Furia25

##### Villager
You will need to loop through all tiles on the map and check the region ID of each one, e.g.
JavaScript:
``var n = 0; for (var x = \$gameMap.width(); x--;) for (var y = \$gameMap.height(); y--;) if (\$gameMap.regionId(x, y) === 111) n++; n``
This is written for use in an eval, e.g. Control Variables -> Script. Explanation:
• `var n = 0;` => initialise tile counter
• `for (var x = \$gameMap.width(); x--;)` => loop through all `x` values
`for (var y = \$gameMap.height(); y--;)` => loop through all `y` values
• `if (\$gameMap.regionId(x, y) === 111) n++;` => +1 to counter if the region is `111`
• `n` => return the value of the counter
Details on the `for` loop in JavaScript:
[SOLVED] Thanks ! Have a nice day

#### slimmmeiske2

##### Little Red Riding Hood

Status
Not open for further replies.

### Latest Profile Posts

Just released a new trailer for Manafinder! It's the TGS trailer! I'm very happy with the result!
sooo... im gonna go ahead and release all my game ideas on android as Beta. Everyone will be nice right? cause its Beta... right?...

AABS traps and heals (detail is below the YTB desc)
I may actually have something I can put into the Boss Battle Build Bout by the time it’s due. It won’t be anything spectacular (or even great (and maybe not even good (I have no idea how to do combat (yay for nested parentheses)))), but I might have a submission none the less.
Today's my first login since Jan 2020. Time sure flies. Sorry to everyone's messages i missed.