Do something after map is loaded

MothaFlippin

Warper
Member
Joined
Jul 4, 2016
Messages
3
Reaction score
1
Primarily Uses
Hi guys, so I have been using RPG Maker since VX, used Ace but never really got into it too much, but now with MV and with JavaScript as the scripting language I have gotten back into the RPG Maker series.

So, I have started creating a plugin to make certain Region IDs act as "walls" (I know there are some things like that around already, but I'm doing it more for the practice), and to do that I have given each map a tag ("unw") that gives the ID of what region should act as "unwalkable" (example: <unw:3>), then I'm running the command:

$dataMap['meta'].unw to get the id of each tag, however, what happens is, when I run this command and start the game, the script seems to happen before the map loads returnign the message:

"Cannot read property 'meta' of null", interrupting the rest of the script and preventing it from happening.

So I have been searching with no results for a way of running the "$dataMap['meta'].unw" after the map is loaded, any suggestions?
 

Kino

EIS Game Dev
Veteran
Joined
Nov 27, 2015
Messages
556
Reaction score
795
First Language
English
Primarily Uses
RMMV
The best place to put it would be to load that information somewhere in the Scene_Map.prototype methods


For example, you can put it inside of the Scene_Map.prototype.initialize; this method is called whenever a player goes to the map scene. So, in that case.



var SceneMap_initliaze = Scene_Map.prototype.initialize;
//We are aliasing here, so we can get any previous code inside of the initialize function before we change things.

//Next
Scene_Map.prototype.initialize = function() {
SceneMap_initialize.call(this);
//Calling the original code here
//Now, we can write code to look for the regions aka $dataMap stuff.
$dataMap['meta'].unw -- etc
};




This would make sure that $dataMap exists at the time of the call, and is not null.


$dataMap only exists once you're on a map scene anyway.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
I'm not sure what you're attempting to do.  If you add a <unw:3> tag in your map's notes, it is already placed into the metadata when you load the map.  You don't have to make it read it or look for it on loading the map.


All you have to add is the logic to check that tag when the player or an event attempts to move onto a tile.  This would be something along the lines of if $dataMap.meta.unw === $gameMap.regionId(x, y) in the Game_CharacterBase.isPassable function, or something like that.


Make sure there's no space between the : and the 3 in the tag, or it may be that you'll need to convert $dataMap.meta.unw to a number in order to compare.  I think if there is no unw metadata (you didn't put the tag on a map) it'll just return null, but that'd be worth verifying too.
 
Last edited by a moderator:

MothaFlippin

Warper
Member
Joined
Jul 4, 2016
Messages
3
Reaction score
1
Primarily Uses
The best place to put it would be to load that information somewhere in the Scene_Map.prototype methods


For example, you can put it inside of the Scene_Map.prototype.initialize; this method is called whenever a player goes to the map scene. So, in that case.




var SceneMap_initliaze = Scene_Map.prototype.initialize;
//We are aliasing here, so we can get any previous code inside of the initialize function before we change things.

//Next
Scene_Map.prototype.initialize = function() {
SceneMap_initialize.call(this);
//Calling the original code here
//Now, we can write code to look for the regions aka $dataMap stuff.
$dataMap['meta'].unw -- etc
};




This would make sure that $dataMap exists at the time of the call, and is not null.


$dataMap only exists once you're on a map scene anyway.
Hi,

Thanks for the reply, I will try this once I get home, and I will reply with results

_____________________

I'm not sure what you're attempting to do.  If you add a <unw:3> tag in your map's notes, it is already placed into the metadata when you load the map.  You don't have to make it read it or look for it on loading the map.


All you have to add is the logic to check that tag when the player or an event attempts to move onto a tile.  This would be something along the lines of if $dataMap.meta.unw === $gameMap.regionId(x, y) in the Game_CharacterBase.isPassable function, or something like that.


Make sure there's no space between the : and the 3 in the tag, or it may be that you'll need to convert $dataMap.meta.unw to a number in order to compare.  I think if there is no unw metadata (you didn't put the tag on a map) it'll just return null, but that'd be worth verifying too.

Hey,

Thanks for the reply, I understand that this is how it is supposed to work, however when I launch the game, the game starts by LAUNCHING ALL THE PLUGINS first, and THEN loading the first map.
As a result, the $dataMap['meta'].unw returns null for the very first seconds, resulting in the entire plugin crashing before even having a chance to load a map.

(PS: After writing that I just remembered that maybe a simple 'if' can avoid all this)
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
The map metadata is loaded when the map is loaded.  If you do everything properly - in the right order - it just works.  If it's not working, I would question why you're trying to refer to metadata on a map prior to the map being completely loaded?


Where exactly are you referring to this info?  I suspect it's not the correct place.
 

MothaFlippin

Warper
Member
Joined
Jul 4, 2016
Messages
3
Reaction score
1
Primarily Uses
The map metadata is loaded when the map is loaded.  If you do everything properly - in the right order - it just works.  If it's not working, I would question why you're trying to refer to metadata on a map prior to the map being completely loaded?


Where exactly are you referring to this info?  I suspect it's not the correct place.
I have now been able to fix this situation, there were some obvious mistakes that at the time I failed to notice.
Thanks for the help
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
awesome!  Finding the mistakes yourself is so much better than having other people point them out.  You learn much more from the experience :)  


Hope it keeps working for you from here ;)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,035
Messages
1,018,454
Members
137,821
Latest member
Capterson
Top