MZ Js Fetch Problems

Hey i have a problem with this code here. I want to get the FightConfig from a JSON file, but it doesnt really work.
When i log the FightConfig in the InitializeVariables method it returns the correct object, but if i log it later in DoSomething() it doesnt. I'm not sure what the problem is here. Also is there another way to do this. I just want to read a JSON file, without async stuff.

Code:
PluginManager.registerCommand(

  Game.PluginName,

  Commands.InitializeFight,

  async function () {

    await Game.InitializeVariables();

  }

);

PluginManager.registerCommand(Game.PluginName, Commands.UseConfig, function () {

  Game.DoSomething();

});

function NewGame() {

  let FightConfig = null;

  async function InitializeVariables() {

    console.log("InitializedVariables");

    FightConfig = await GetConfig();

  }

  async function GetConfig() {

    return fetch("Config.json").then((res) => {

      return res.json();

    });

  }

  function DoSomething() {

    console.log(FightConfig);

  }

  const Game = {

    InitializeVariables: InitializeVariables,

    DoSomething: DoSomething,

  };

  return Game;

}
With let FightConfig = ... you define its scope.
This scope makes the variable invisible to the DoSomething() function.
With let FightConfig = ... you define its scope.
This scope makes the variable invisible to the DoSomething() function.
No it should be in scope. All functions are inside the NewGame function and thus should have access.
If you don't want to use async stuff, why is there async stuff in the code? Where did you get this?
If you don't want to use async stuff, why is there async stuff in the code? Where did you get this?
Because i dont know another way yet. I would be fine with async if this implementation worked, but it doesn't.

However, I think i found the issue. Apparently async code always gets executed after the synchronous stuff, so the FightConfig is only initialized after DoSomething(). I will look for another method to read json now, because i think it wont work with fetch
Because i dont know another way yet. I would be fine with async if this implementation worked, but it doesn't.

However, I think i found the issue. Apparently async code always gets executed after the synchronous stuff, so the FightConfig is only initialized after DoSomething(). I will look for another method to read json now, because i think it wont work with fetch
Why not use the same method as the default engine config does?
Why not use the same method as the default engine config does?
What method do you mean exactly?
What method do you mean exactly?
Look up StorageManager.saveObject and StorageManager.loadObject.

Original thread: https://forums.rpgmakerweb.com/threads/js-fetch-problems.166500/