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.
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;
}