MV A variable to txt plugin or code without Node.js

Hello everyone!!!

I'm a begginer in RPG Maker MV and I'm trying to make a customizable variable from a text file in my computer, but I need that works in a browser so I can't use Node.js 'cause causes error of Reference like: "file is not defined", "require is not defined", etc. This is when I try to use the fileSystem (fs) and require command of Node.js...

I see a lot of plugins that work in create and put in a text file a game variable or set a game variable from a text file, what is what I'm looking for but always used Node.js and that is a big problem for me.
Another thing I see is the fact that Node.js and specific the require command is impossible to install in the web browser version of the rpg maker deploy.

BTW, sorry for my paleolithic english I try my best to found a answer for this issue so I'm in complete gratitud from anyone who give me a response.

I'm all ears, any suggestion is welcome.
Kisses and have a nice day.
You can check out DataManager.loadDataFile(name, src). This function loads a file and makes it globally available. It is asynchronous, so you have to wait until it's available.

Example:

Your file, let's call it "props.json":

JSON:
{
  "myVariable": 5
}

Your plugin:
I alias a function so your file is loaded on starting the game

JavaScript:
const alias_DataManager_loadDatabase = DataManager.loadDatabase;
DataManager.loadDatabase = function() {
  alias_DataManager_loadDatabase.call(this);
  this.loadDataFile('$props', './data/props.json');
}

Then you can read your variable like this:
const data = $props.myVariable;

Let me know if it works for you.
You can check out DataManager.loadDataFile(name, src). This function loads a file and makes it globally available. It is asynchronous, so you have to wait until it's available.

Example:

Your file, let's call it "props.json":

JSON:
{
  "myVariable": 5
}

Your plugin:
I alias a function so your file is loaded on starting the game

JavaScript:
const alias_DataManager_loadDatabase = DataManager.loadDatabase;
DataManager.loadDatabase = function() {
  alias_DataManager_loadDatabase.call(this);
  this.loadDataFile('$props', './data/props.json');
}

Then you can read your variable like this:
const data = $props.myVariable;

Let me know if it works for you.
Hey!!! Thx u so much it works for me, I add part of the code in the main rpg_objects.js file to reload the variable every time a text window opened:

Game_Interpreter.prototype.update = function() { while (this.isRunning()) { if (this.updateChild() || this.updateWait()) { break; } if (SceneManager.isSceneChanging()) { break; } if (!this.executeCommand()) { (function() { DataManager.loadDataFile('$props', 'props.json') })(); break; } if (this.checkFreeze()) { break; } } };
Lines 8830 to 8848

The "function" part of the code is the part of the code one you send me and I fix a problem in the ('$props', 'props.json') part of the code, the json file now stores in the data folder correctly. The plugin is installed for the case of the "myVariable" is null, so that is solved in that case.

That's all, I maked the deploy and works perfectly in the web version.
Thx u again, now I can use a rpg maker mv project with any text editor from any another program.

I used this to make a project of twitch subs avatars connected with obs using the game as a browser source and used a twitch bot that extracts the names and outputs them to the json file you provided.

Today I achieved a victory and it is thanks to you so I wanted to put it in writing uwu
@P3G450 dont alter the core files directly unless you know what you do,
it's best to copy the part and alter it by than,and place it in your plugin database.

so if the engine update, you keep the changes, else it is removed 🙂

but it's just a slight warning ^^

good luck with your project further.

Original thread: https://forums.rpgmakerweb.com/threads/a-variable-to-txt-plugin-or-code-without-node-js.152710/