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.




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:



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);


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:




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.



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,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
[closed]IgnoreMe[/closed]
 
Status
Not open for further replies.

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,049
Members
137,569
Latest member
Shtelsky
Top