The usefulness of regions? What are their limitations?

I know there's already a lot that can be done with regions-- setting collisions, restricting movement, adding interactive terrain and so on. I also know how they are stored in the $dataMap file... but I want to know if it's possible to add more functions to make it easier to search a map for region information, like an easy way to get the location of those tiles. Basically, a way to do the opposite of the $gameMap.regionId(x,y) function: finding the x and y values of region tiles in a (hopefully) efficient manner... and then being able to use that information for practical purposes...


An in-depth description of what I hope to use it for is detailed in this topic, in case it makes my train of thought any clearer... however I'm not really looking for answers to that problem specifically, because I'm clearly lacking a more fundamental understanding of the features of RMMV.




(I know it's in the "plugin requests" section, but I'm really the type that likes to do everything by herself and not knowing how to solve this is seriously bugging me so I'd rather get clarification than have someone magically solve things for me. There are other things I want to do with regions, anyway. so many questions that i think it would be overwhelming to ask all of them in a single topic)


Right now, I'm just trying to get a grasp on how versatile the region feature is, really, and what its limitations are.


From what I understand of the default code, the engine ignores regions completely unless the player is standing on top of one, or if you check for an id by manually pointing to an x,y coordinate (whether it be the semi-arbitrary like coords of an event, or static like a couple of inputted number values).


By default, you can't check if the player or an event is fenced in by a region (only if it's standing on top of a filled-in region area), or if it's standing between 2 different regions, etc. Region restriction scripts that I've looked at don't really activate unless a character is adjacent to a restricted region/tries to move onto it, which is basically the same as how the engine handles regular tile collision.


You also can't simply say "hey game, return ALL tiles marked with region (0-255) with an X value of 7". In order to do that, as far as I know, you'd have to add a function that loops through ALL tiles of the map and then stores their values into a large array/object(s), and then have it search every one of those indexes for matching X and region ID values.


I know javascript is supposed to be pretty fast, but the above method feels pretty redundant to me, when that data should already be stored in the $dataMap object (which can be retrieved using $dataMap.data[(5 * map height + y) * map width + x]). in a 50x50 map, (7,1) is 12557 and (7,2) is 12607 and so on. But for the formula to work it still needs a specific coordinate so it knows what index to look for in that massive array of tiles, unless you go back to the looping method to return everything into an array. Is that really the only way? I see the pattern there, but... is it really a practical way to do it? My worry is that it affects performance. Chances are I am looking at the problem from the wrong angle entirely.
If the code is just executed once in a while, it doesnt matter if its unclean and long and weird, there will be no noticeable


difference between the ugly code and clean code.


Only if you have paralell functions which run often in a seccond it can be important to not missuse some comands and maybe to code it clean.


I agree you maybe looking from the wrong angle.


With the Map Camera stuff, you dont need regions, you need a pluginn that allows disabling the auto scroll function of the map.


I dont know if such stuff allready exist.


Or you need to make a mechanic so an event becomes the Hero and the standard Player wil be used as Camera.


That would cause more Problems than it would solve.
Okay, it's good to know Javascript is fast enough to be able to handle some messy code. I know ruby could be really slow sometimes. I try to keep my parallel processes to a minimum.


As for the map camera thing... I was able to actually execute my map camera locking idea using 4 variables (2 variables for the x and y origin of the area, and then 2 more for the area's width and height. the game only paid attention to these variables if a map notetag contained "<segmented>"). It worked, but wasn't very efficient-- I had to set these values manually (like every time the player transfers to another part of the map, I'd have to change the values of all 4 variables to the correct coordinates), and if I ever decided to make changes to my map I'd have to edit every instance of that variable manually. Using regions would make changes much easier to accomplish, and also add the possibility of even having oddly-shaped maps like T-shapes or L-shapes, which is a really cool idea that saves some mapping work.


But if the region idea is actually not possible, I may just deal with the variables thing. It's clunky but it works. Making an event take the place of the hero could cause a lot of problems trying to interact with events that are near the edge of the area.
Iam no scripter and my expirience is with ruby not javascript, but it should be still true. maybe a script pro can confirm?


I dont understand the region idea solution. So i didnt ment that its impossible.


Which commands are you using to prevent the map from scrolling? or are you counterscrolling with eventcommand scroll map?


Understanding how you do it can help us helping you to set up the rest of the mechanic.
The variable solution I came up with is something like this:


Imagine the 4 variables are making a rectangle shape. I declare the variables used for this in the initialization of the game map...

Spoiler
Game_Map.prototype.initialize = function() {
// all default init stuff goes here
this._sectionOriginX = 0;
this._sectionOriginY = 0;
this._sectionWidth = 25;
this._sectionHeight = 18;
}

Game_Map.prototype.sectionOriginX = function() {
return this._sectionOriginX;
}
Game_Map.prototype.sectionOriginY = function() {
return this._sectionOriginY;
}
Game_Map.prototype.sectionWidth = function() {
return this._sectionWidth;
}
Game_Map.prototype.sectionHeight = function() {
return this._sectionHeight;
}

sectionOriginX, sectionOriginY, sectionWidth, and sectionHeight would all have to be set manually every time the player moves to another section of the map. It's possible to make functions to make it a little faster to change them, but they still have to be called every time, and a problem that could arise is that it treats other map segments as nonexistent when they aren't active.


And I also make a new function to check if the map is supposed to have a segment-locked camera...


Game_Map.prototype.isSegmented = function() {
return this.meta.segmented; // returns true if the map's notebox has <segmented> in it (I know there are more elegant ways to do this.)
}


And then, I change the default scrolling behavior of the camera


Game_Map.prototype.scrollDown = function(distance) {
if (this.isLoopVertical()) {
//stuff for vertical looping maps
}
} else if (this.height() >= this.screenTileY()) {
var lastY = this._displayY;
if (this.isSegmented()) { // this is where I made alterations.
this._displayY = Math.min(this._displayY + distance,
this.sectionHeight - this.screenTileY()); // since it's scrolling down, it uses the sectionHeight variable
} else { // for regular maps, it uses the default script...
this._displayY = Math.min(this._displayY + distance,
this.height() - this.screenTileY());
}
this._parallaxY += this._displayY - lastY;
}
};


(I do the same for scrollLeft, scrollRight, and scrollUp functions using the appropriate variables.)


It is really clunky though, and with some more work and some regExps I could maybe have every segment in the map defined from the get-go using the map's notebox. It's better, but still a lot of manual number inputs. Maybe using regions is too-good-to-be-true, but they just seem like they have so much potential. I'm still a scripting novice.
Update: I solved the problem I was having. Instead of calculating arrays for the entire screen, I calculated arrays for the edge tiles of the screen only. Also figured out how to have the camera adjust its position properly when transferring maps. So, now I can freely draw boundary regions onto my maps and the camera snaps to them 🙂


Made a function like this for each direction:


Game_Map.prototype.lockDown = function() {
var regions = [];
var origin = Math.floor(this._displayX);
var range = Math.floor(this._displayX + this.screenTileX() - 1);
for (i=origin + 1; i < range; i++) {
var regionId = this.regionId(i, this._displayY + this.screenTileY());
regions.push(regionId);
}
if (regions.indexOf(boundaryRegion) > -1) {
return true;
}
};


and then had to overwrite the scrolling functions like so:


Game_Map.prototype.scrollDown = function(distance) {
if (this.isLoopVertical()) {
this._displayY += distance;
this._displayY %= $dataMap.height;
if (this._parallaxLoopY) {
this._parallaxY += distance;
}
} else if (this.height() >= this.screenTileY()) {
var lastY = this._displayY;
if (this.lockDown()) {
this._displayY = lastY;
} else {
this._displayY = Math.min(this._displayY + distance,
this.height()- this.screenTileY());
}
this._parallaxY += this._displayY - lastY;
}
};


It breaks with any added camera plugins, which kinda sucks, but other than that it works really well. It supports oddly-shaped maps too, though they are too quirky/fussy to navigate to use on a regular basis. After I clean it up a bit I may release it as a plugin.

Original thread: https://forums.rpgmakerweb.com/threads/the-usefulness-of-regions-what-are-their-limitations.62596/