OKIComputer

Villager
Member
Joined
Mar 20, 2016
Messages
17
Reaction score
8
First Language
English
Primarily Uses
This is a pretty simple question, I'm trying to learn javascript/RPG Maker MV and how the core of RPGMaker MV's objects are layed out. I want to add a 2D array to the map objects for my game. This array will store whether the player has walked on a given tile or not: when the player walks on the tile, it becomes true. Real simple stuff. My question is, where should I declare that value? In what object?
 
Last edited by a moderator:

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,699
Reaction score
939
First Language
English
Primarily Uses
N/A
Well, first thing's first, unfortunately, JavaScript does not support multi-dimensional arrays. However, this is easy to fix, because technically, there's no such thing as a multi-dimensional array, and languages that appear to support it just do a little extra math behind the scenes to make it seem like it exists. The formula for the index in a two dimensional array (assuming we're using x for width and y for height) is:


var index = (y * height) + x;






Now that that's out of the way, where to put the variable depends on several things. What is going to need to access this array of walked-over tiles? What do you intend to use it for? Is it safe for any object with access to be able to change the array, or are there only a few spots that should be able to edit the values to ensure everything is valid?


Since you say you want to add it to the map, and I assume this may just be part of a learning exercise, or perhaps some kind of system you're working on to familiarize yourself with MV, we don't really need to go through a whole list of scenarios, because I'm assuming this is mostly designed as a learning experience. Personally, since your array will be based on the current map, I'd recommend putting it in Game_Map, which is re-setup (i.e. the setup function is called) for each map that's loaded. By putting the array in there, with the code to set it up, you're pretty much guaranteed that it'll apply to the current map.


If you haven't already seen it, I highly recommend that when you're developing plugins or changing the code for the engine to better fit your game, that you have the rpg_* files split up by class, as looking through the smaller files that are organized by name is significantly less intimidating than looking through five or six files of 10,000+ lines of code. I maintain a list of spit files for almost every version of RPG Maker MV (I think I missed 1.3.2 because it was short-lived or something) in this topic.
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,634
Reaction score
1,452
First Language
French
Primarily Uses
RMMV
am not sure understand all , but if this, can help you a little bit.


// function check if on the title
$dataMap.titlecheck = function (tile,ppos){
if (ppos[0]===tile[0]&&ppos[1]===tile[1]) {
return true}return false
}


var ppos = [$gamePlayer._realX,$gamePlayer._realY]// Get the player pos in array
var titlepos = [[19,14],[10,15],[5,5]] // you title pos in 2D array
$dataMap.titlecheck(titlepos[0],ppos);// after call the function is your on the title you will get true or false , titlepos[0] to test the tite 1 titlepos[1] for the tite 2 ....


you can put this in console log and change titlepos, to understand how is work.
You will get true or false
 
Last edited by a moderator:

OKIComputer

Villager
Member
Joined
Mar 20, 2016
Messages
17
Reaction score
8
First Language
English
Primarily Uses

OK, thanks. That thread/resource looks very helpful as well, thank you. I'm trying to build up to a minimap system with a fog of war feature. So I want to be able to record where the player has been/seen. I've done a lot of editing of stuff and adding some functionality to already existing stuff for menus, mechanics etc., this is a bit more 'start from scratch' so I wanted to make sure I was starting in the right area.
 

Zalerinian

Jack of all Errors
Veteran
Joined
Dec 17, 2012
Messages
4,699
Reaction score
939
First Language
English
Primarily Uses
N/A
I see, alright. I assume you'd want to be able to store the information of what's been seen so it can be reloaded when you revisit a map, which could potentially add a bit of work to the plugin overall, depending on how you decide to store the information. 
 

Latest Threads

Latest Posts

Latest Profile Posts

unknown.png

A sketch of a character for an upcoming chapter. I am pre-preparing the heck out of this one and future chapters, don't want to spend time figuring the story out again. :blush:
Today *Fix the game UI
RMMZ maxRows make me tired.
The game supports real-time language switching (really interesting).
8laFKAa.png


jBYDFzZ.png


lYbvPth.png

mY99lgU.png

Swag collecting in the new randomly generated area. Now the mini map also shows the randomly generated features... And even illustrates the whole "bubble" system" that I made to manage memory... Though that part's inadvertent. We'll just call that "the fog of war"... Yes, that's what we'll do. Nobody will be the wiser! :kaopride:
not me being not lazy for 5 seconds and drawing another char portrait (her name is hazel)
its_hazel.png
Been a while since the last time I made a song remix. Had a blast making this

Forum statistics

Threads
110,456
Messages
1,053,452
Members
143,548
Latest member
Dolidodzik
Top