MV RegExp Returning NaN!

Ok, so the battle system I use, LeTBS (LeCode's Tactical Battle System) is supposed to have this feature where I can assign an enemy's troop index into an enemy cell's note box. At first, I thought the feature was broken, but upon further investigation, it seems that it's returning NaN under the hood. Let me explain...

I put <Enemy Cell: 0> & <Enemy Cell: 1> into the note box of 2 separate events on the map, which represents the enemies as visible/on map monsters. Normally, it should be <Enemy Cell> w/o the index mentioned, but that results in each event loading a random monster from the enemy troop. This sometimes (50% chance w/ troop size of 2) results in seeing monster A on the map, but then it turns out to be monster B once combat begins. Very immersion-breaking!
Spoiler: Before Combat
1645605865310.png
Spoiler: During Combat
1645605876389.png
Anyway, I did some console logs and pinpointed the fault to a Regex in LeTBS.js. This is the relevant block of code:
JavaScript:
BattleManagerTBS.createStartCells = function () {
    this.getLayer("scopes").clear();
    this._startCells = [];
    $gameMap.events().forEach(function (eventObj) {
        var x = eventObj.x;
        var y = eventObj.y;
        var note = eventObj.event().note;
        var data = {};
        if (note.match(/<Enemy Cell>/i)) {
            data.type = "enemy";
        } else if (note.match(/<Enemy Cell\s?:\s?(.+)>/i)) {
            data.type = "enemy";
            data.fixed = Number(RegExp.$1);
            console.log(data.fixed); //testing...
            console.log(data); //testing...
        } else if (note.match(/<Actor Cell>/i)) {
            data.type = "actor";
        } else if (note.match(/<Actor Cell\s?:\s?(.+)>/i)) {
            data.type = "actor";
            data.fixed = Number(RegExp.$1);
        }
        if (data.type) {
            var cell = new TBSCell(x, y);
            cell._event = eventObj.event();
            cell._positioningData = data;
            this.createPositioningCell(data.type, x, y, cell);
            this._startCells.push(cell);
            if (!this._entitiesEvents[x])
                this._entitiesEvents[x] = {};
            this._entitiesEvents[x][y] = eventObj;
        }
    }.bind(this));
};
The console logs yielded the following:
1645605443336.png


In short, data.fixed is supposed to return the number that I put in <Enemy Cells: index>, where index should be a number. So if I write <Enemy Cells: 1> then the RegExp should return "1". However, I'm getting NaN...😔

This is the RegExp btw: else if (note.match(/<Enemy Cell\s?:\s?(.+)>/i)) {
Several things you can try

- Change RegExp to /<Enemy Cell\s*:\s*(\d+)>/i
- Print out RegExp.$1 instead.
- Change RegExp.$1 to const match = note.match(/<regex>/) (retrieving the $1 value by calling match[1] instead) because $1 is already a deprecated function. Might be also because $1 stored the wrong value/unreliable.
Several things you can try

- Change RegExp to /<Enemy Cell\s*:\s*(\d+)>/i
- Print out RegExp.$1 instead.
- Change RegExp.$1 to const match = note.match(/<regex>/) (retrieving the $1 value by calling match[1] instead) because $1 is already a deprecated function. Might be also because $1 stored the wrong value/unreliable.
That did it, thank you! No more NaN!😤
1645609102812.png

Original thread: https://forums.rpgmakerweb.com/threads/regexp-returning-nan.145176/