MZ Plugin to create a txt from variables

Hello,

Sorry non native speaker.

I`ve come to you for help. i`m working on a RMMZ project that is intended to help young adults choose an educational path. Several jobs are described and then there are some tests in math, logic, grammar and stuff.
Depending on the results the YA will be further counseled.

The test are working, the results are saved in variables 1 to 5, in Nr. 6 the name of the testee is saved.

The thing is... I want to export the values of the variables to preferable excel but even txt would be fine.
SInce I don`t know any programmer or javascript myself I asked Chat GPT 4 for help and it created this plugin fpr me:

/*:
* @target MZ
* @plugindesc Exports variables 1 to 6 to a text file
* @command ExportVariables
* @text Export Variables
* @desc Exports variables 1 to 6 to a 'variables.txt' file in the game directory.
*/

(() => {
const pluginName = "ExportVariablesToTxt";

PluginManager.registerCommand(pluginName, "ExportVariables", args => {
const fs = require('fs');
const path = require('path');
let variablesData = "";

// Gather variables 1 to 6
for (let i = 1; i <= 6; i++) {
variablesData += `Variable ${i}: ${$gameVariables.value(i)}\n`;
}

// Define the file path
const filePath = path.join(path.dirname(process.mainModule.filename), 'variables.txt');

// Write the data to the text file
fs.writeFileSync(filePath, variablesData);
console.log('Variables 1 to 6 exported to ' + filePath);
});
})();

I can run the Plug-In command but neither in Test Mode nor in Game Mode a file is created. It`s getting kind of frustrating.

Is it that I don`t have entered a real directory to save? Or where is the coding error?

Any help would be really appreciated...
SInce I don`t know any programmer or javascript myself I asked Chat GPT 4 for help
This is not a very good idea. The Internet is covered with articles about how ChatGPT writes at the level of a 4th-grader and gets math problems wrong.

Generators, by definition, make things up - it doesn't make much sense to me to ask it to do something (like code) that will only work if every letter in every word is perfect. (and not to pile on, but you as a teacher/counselor/whatever should have the professional knowledge to know better)

That said, did you name the file correctly? If you don't follow the instructions and name the plugin ExportVariablesToTxt.js, the plugin command won't function.
Yes, I know that and sey I did. I can select the plugin and can use the plugin command in my event.

But it doesn`t create a file.

The "Hello World" and an actor randomizer it wrote worked perfectly.
Hello and happy holydays to you all.

The Problem is solved. I worked out a script to export the variables to csv and then I can manually import them in Excel.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/plugin-to-create-a-txt-from-variables.164080/