Status
Not open for further replies.

p0_boy

anti-kumbaya
Veteran
Joined
Mar 26, 2019
Messages
64
Reaction score
29
First Language
English
Primarily Uses
RMMV
Aloha, folks-

I have a plug-in with the following function (MapCrowd()):

Code:
// Reads current map's [Note] field and assigns events to specified regions.
    function MapCrowd() {

        // Check that <clone> tag is present in [Note] field.
        if ($dataMap.meta.clone != undefined) {

            let clone_event = 0;

            // Separates multiple RegionIds/Events and places them in an array.
            let crowd = ($dataMap.meta.clone.replace(/\s/g, ``)).split(`;`);

            // Perform placement of events on regions.
            for (let clones = 0; clones < crowd.length; clones++) {
                let temporary = crowd[clones].split(`|`);

                let regionId = Number(temporary[0]);
            
                // Checks if event source is internal or external source (CloneBank.json)
                if (isNaN(temporary[1]) === true) {
                    if (temporary[1].charAt(0) === `$`) {
                        let clone_bank = RootFolder() + `/data/` + `CloneBank.json`;

                        if (FileExists(clone_bank) === true) {
                            let raw_json = load_text_file(clone_bank);
                            let clone_objects = JSON.parse(raw_json);

                            clone_event = Object.assign({}, clone_objects.events[temporary[1].substr(1)]);

                        }
                    }
                } else {

                    clone_event = Number(temporary[1]);

                }

                // Place events on specified regions.
                if (clone_event != 0) $.PlaceEvent(clone_event, regionId);

            }

        }

    };

As the comments in the code remark, it basically reads the <clone> tag from the [Notes] field of maps, and places events on specified regions.

map-note.png

region-map.png


After placing MapCrowd() in aliases of Game_Map.prototype.setup, Game_Map.prototype.setupEvents, Scene_Map.prototype.initialize, and getting errors (to do with trying to read meta of null, I assume because $dataMap had not yet been loaded), I finally got it working by placing it in
Scene_Map.prototype.onMapLoaded:
Code:
    // Executes upon map load.
    var alias_Scene_Map_onMapLoaded = Scene_Map.prototype.onMapLoaded;
    Scene_Map.prototype.onMapLoaded = function() {

        // Established map load routines.
        alias_Scene_Map_onMapLoaded.call(this);
    
        // Plug-in addendum.
        MapCrowd();

    }
This was only partially successful though (please excuse the rudimentary graphics):


Everything loads okay, however a TypeError occurs after I exit the game menu:
typeerror.png

error.png

error2.png

I am hoping that somebody can point me to a better way that I can go about running MapCrowd() upon loading of a map?

Thank you in advance!


EDIT (08/06/2019 7:26 AM [GMT +8]):

The problem doesn't have to do with Scene_Map.prototype.onMapLoaded as I originally assumed, it seems to be a problem with dynamically creating events.

As a comparison, I removed the plug-in that I wrote and tried to use another, similar plug-in that I found (while scouring Google for a solution)- Alphaxaon's EventWrapper.js.

I typed the following commands in the console (as per the plug-in's instructions):

Code:
var event = new MapEvent();

event.copyActionsFromEventOnMap(1,1);

event.spawn(2,4);

eventwrapper.png


And it seemed to be all gravy, until I tried entering and exiting the game menu again and encountered the same "Cannot read property 'pages' of null" TypeError:


scenemanager-error.png


Does anybody know what I am doing wrong?

I have disabled all other plug-ins except for Community_Basic, so I know there aren't any external conflicts.

plugin-window.png


Any help would be much appreciated. Thanks!


EDIT 2 (08/06/2019 12:15 [GMT +8])

Since nobody seems to have a clue about this, I just re-wrote my plug-in to use Galv's Event Spawner as the method for creating the events.

It's kind of a pain because the Galv's plug-in requires the use of a "Spawn Map" to draw events from, but at least it isn't giving me the TypeError any more.

Below is the less exciting, MapCrowd() revision.

Code:
    function MapCrowd() {

        if ($dataMap.meta.clone != undefined) {
          
            let crowd = ($dataMap.meta.clone.replace(/\s/g, ``)).split(`;`);

            for (let clones = 0; clones < crowd.length; clones++) {
                let temporary = crowd[clones].split(`|`);

                let regionId = Number(temporary[0]);

                let clone_event = Number(temporary[1]);

                PlaceEvent(clone_event, regionId);

            }

        }

    };

PlaceEvent() calls Galv.SPAWN.event to create the events.

Subsequently I also had to rewrite a few other things to get everything working again- Galv's plug-in uses a custom global $dataSpawnMap, which I needed to reference (instead of $dataMap) to read the [Note] field of the newly spawned events.

That's all folks!
 
Last edited:

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,466
Reaction score
11,940
First Language
English
Primarily Uses
RMVXA
[closed]IgnoreMe[/closed]
 
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

just when I thought one of the greatest game of all time couldn't get any better, they announce a new dlc for it.
For anyone interested: there's another huge humble bundle with JRPG assets + a game jam starting next month - it's for a good cause, so check it out <3
Turning a specific vibe into reality is incredibly difficult. For instance, this song is one of the ones I listen to when working on my post apocalyptic project, and getting it's "feeling" into the game has been a real challenge.

I don't just wanna regurgitate the numbers I see, I wanna actually understand the calculations I'm making so I'm probably gonna make a post later with some calculations and what I THINK they mean to get some advice and corrections.

Edit: All (Most) of these will be tested in game prior. I just wanna make sure I understand what's going on under the hood if you will.
my girlfriend calls all my little chibi art cute lol... funny considering that wasn't the original art style of the game.

Forum statistics

Threads
113,778
Messages
1,077,373
Members
147,808
Latest member
traviscot
Top