Fail (and succeed) to set map data to a variable

Hi, I have a problem in MV.

I developed 2 plugins. Both have DataManager.loadDataFile function to load map database. The first plugin run flawlessly. But the second plugin failed to set map data to a variable (lets say $dataMapSomething). That $dataMapSomething left as undefined when I checked it using console.log directly after loadDataFile line.

And there's more of it, when I checked again by typing manually on console (the game window still shows error screen), that $dataMapSomething is already set with map data which I want to set before.

The only difference I could tell between those two plugin is the working one calls DataManager.loadDataFile on the inialization of scene map. The failed one calls it from game interpreter command.

Could any of you guys tell me what I've done wrong?

Thanks!
You may need to wait a while for the file to be loaded.  I found when I was writing my LazyTilesets plugin ('cause I wanted to do it immediately on launch) that even though the command had been issued to load the files, the results weren't available immediately like they are in Ace.
Thank you Shaz. I was thinking that could be the case but had no idea how to check it.

Forgive my ignorance but could you tell me how to check wether a data has already loaded on a variable (and probably how to declare "wait" method until it has been fully loaded). I'm still struggling to read JS syntax and the whole MV's workflow.

On the other hand, your answer has raised another question of mine. We were speaking about loading external data so it maybe take some time to process. Is there any possibilities thay "internal" data could also need some time to be calculated or processed (we're talking about standard MV methods, not complicated ones) before it could return the final result?

Any kind of help on this problem will be apreciated. Thanks.

Original thread: https://forums.rpgmakerweb.com/threads/fail-and-succeed-to-set-map-data-to-a-variable.47300/