Length of database before "New Game"

It's hard to explain... I added a property to both actors and enemies in a plugin I'm trying to make. I tried to give it values for different enemies and actors with notetags, from the database, but everytime I try to check the length of Game_Actors, or $gameActors, it returns 0 or undefined in the main function. Dev Tools snipped for me that it's trying to do it before clicking "New Game" or "Load Game".

Spoiler: The function for actors, shortened goes like...
(function() {
[...]
Game_Actor.prototype.personalizedIntParam=0; //Pre-initialized just in case
Game_Enemy.prototype.personalizedIntParam=0;
[...]
for (var i = 0; i < $gameActors.length; i++) //Crash
{
if ($gameActors.actor.meta.personalizedIntParam)
$gameActors.actor.personalizedIntParam=parseInt($gameActors.actor.meta.personalizedIntParam)
}
[...]

})();

As I said before, I tried every combination I could think of, using that online spreadsheet for reference, and devTools to have a guess on what's what.

I know that the parameter is applied perfectly fine on every character, as $gameActors.actor(2).personalizedIntParam returns 0, both in dev tools and in-game, instead undefined, even before "New Game".

So I want to know how to check the size/length of the database on running the game.
Dev Tools sounds right - you're trying to access it before it's defined. So the bits of your script that you snipped out are the bits that will reveal where and how you're trying to access it, and as you didn't provide them, we can't comment on them 🙂
what you're missing here is that a lot of data from the database is only loaded from the files and initialized as data after you hit "new game", it doesn't exist (other than files on the HDD) before the new game functions have set the data up.

That is why it's important to know the frame of when the functions is called like Shaz mentioned above.
But I can extract $gameActors data before pressing new game or load game, that means it has to be already listed somewhere.
You can make a script for example...
Spoiler
(function(){
alert($gameActors.actor(1).name);
})();
and it will show a pop up with "Harold" (since 0 is null in the database), before you can click new game, so the array does exist already.
Is there really no way to get the size of it until new game?

I also put the comment on where it crashes. The [...] are parts of still unnecesary code, like a Math.random()... so I don't know what do you want me to share, as it's meant to run when it does... I don't know enough of RPG maker scripting to make it run only after the player presses new game, and I want it to not have any plugin call.
Spoiler: Also, on previous tests of others' plugins...
[edit]What's more, if you use any of these copy actors plugins, copy actor 5 to position 10, leave to title, then press new game and add the actor 10, you get the copy, as it's cached until you close the game. But if you load a game after restarting the game, with a copied actor out of the JSON file's limit, then press new game and try to add it, you get a empty actor.
The $gameActors object exists when the game loads. That doesn't mean it's got anything in it. It only gets something in it when you use the Change Party command.

Perhaps you mean $dataActors instead? That, too, exists when the game loads. But it doesn't have anything in it until the DataManager.loadDatabase function has been called, and completed. Remember MV does asynchronous loading, so just because the function has returned, doesn't mean there's any data populated.

As already said - without knowing how and where you're calling it, we can't help you. If that entire thing is one function and you don't have any functions inside of it, then yes, it's going to run those commands before the database has been loaded.
you need wait DataManager.isDatabaseLoaded() befor use data manager ''gameActors '' in your plugin or script.

PHP:
Scene_Boot.prototype.isReady = function() {
    if (Scene_Base.prototype.isReady.call(this)) {
        if(DataManager.isDatabaseLoaded() && this.isGameFontLoaded()){ // rmmv loaded
            if(pixiSA._loaderFinish){ //ALSO WAIT ALL PIXILOADER IN PROJECT
                return true;
            }else{ // here your stuff use the datamanager
                pixiSA.initialize();
                return false;
            }
        }
    } else {
        return false;
    }
};
The $gameActors object exists when the game loads. That doesn't mean it's got anything in it. It only gets something in it when you use the Change Party command.

Perhaps you mean $dataActors instead? That, too, exists when the game loads. But it doesn't have anything in it until the DataManager.loadDatabase function has been called, and completed. Remember MV does asynchronous loading, so just because the function has returned, doesn't mean there's any data populated.

As already said - without knowing how and where you're calling it, we can't help you. If that entire thing is one function and you don't have any functions inside of it, then yes, it's going to run those commands before the database has been loaded.
The code is meant to run on start, the code can be written on any new js file plugin removing [...], then enabling it from rpg maker. I know it's probably not a good idea despite a couple of benefits I would get if it worked, so I'd be ok if I just learned how to make it wait until the databases are loaded, from new game or load game. I find weird that they are not loaded when I can access their info.


you need wait DataManager.isDatabaseLoaded() befor use data manager ''gameActors '' in your plugin or script.

PHP:
Scene_Boot.prototype.isReady = function() {
    if (Scene_Base.prototype.isReady.call(this)) {
        if(DataManager.isDatabaseLoaded() && this.isGameFontLoaded()){ // rmmv loaded
            if(pixiSA._loaderFinish){ //ALSO WAIT ALL PIXILOADER IN PROJECT
                return true;
            }else{ // here your stuff use the datamanager
                pixiSA.initialize();
                return false;
            }
        }
    } else {
        return false;
    }
};

This is the kind of thing I'm the need of... I have to make something similar and stick it together.

I see it's a overridden version of a function in rpg_scenes.js to make sure all the important stuff is loaded, but I still don't understand how to make use of it. If I set it on a "if" condition, it will just skip the result, on any kind of loop, it will leave the game stuck before drawing the start scene (Another evidence that it is running too early), and if I follow that example per se and add a few lines, I get that pixiSA is still undefined. Of course, if I comment the lines with pixiSA, any Game_Actors.length, $gameActors.length, $dataActors.length returns undefined yet again.
here's how you can proceed.
There are many other ways, I chose this one for me, because it allows me to easily update my plugins.

example a core plugin
PHP:
Scene_Boot.prototype.isReady = function() {
    if (Scene_Base.prototype.isReady.call(this)) {
        if(DataManager.isDatabaseLoaded() && this.isGameFontLoaded()){ // rmmv loaded
            if(myPlugin1._loaded && myPlugin2._loaded && myPlugin124._loaded){ //All my plugin are loaded
                return true;
            }else{ // initialise my plugins
                myPlugin1.initialize();
                myPlugin2.initialize();
                myPlugin124.initialize();
                return false;
            }
        }
    } else {
        return false;
    }
};

And in loading plugin phase in your child plugin
PHP:
    myPlugin1.prototype.initialize = function() {
        if(this.pluginStarting){return;}
        Object.defineProperty(this, "pluginStarting", { value:true }); // one time initialisation.
            // do stuff,
              console.log('$dataActors.length: ', $dataActors.length); // work
// when plugin finish
this._loaded = true;
     };
this technique also makes it possible to manage a multitude of pixi loader.
suppose you need a general plugin that can be named MY_GAME_CORE_plugin and manage all the other plugins.
Then, you're not overriding that function but modifying the original one from rpg_scenes.json, right?

[EDIT]
Now it's the whole plugin undefined. I really don't understand JS for RPG Maker...

Original thread: https://forums.rpgmakerweb.com/threads/length-of-database-before-new-game.90517/