This is probably one of the stranger inquiries on the forum, but I'm wondering if there is a way for MZ to write to a custom INI file? Specifically off an Event Tile activation? I've been searching for any plugin or tutorial that can help me out, but haven't been lucky yet.
My idea on how I wish to use RPG Maker MZ is both creative and clever. I'm a streamer by trade and the streaming bot I use for my streams can read INI files and trigger certain events during stream based on key values that are saved in INI files I have set up. Then it got me wondering, "If RPG Maker MZ had a plugin that could allow me to write to an INI file, my streams could become even more of a community game/adventure than they already are!" Since at that point I'd have a direct communicative Rosetta Stone (if you will) between RPG Maker, the streamer bot, and my community to go on even crazier immersive adventures of my design.
Any help to shed some light on this inquiry would be greatly appreciative. I'm not too well versed in programming nor RPG Maker MZ's inner workings, but I'm willing to learn if pointed in the right direction.
ANSWER FOR FUTURE CURIOUS MINDS:
Please take note:
My idea on how I wish to use RPG Maker MZ is both creative and clever. I'm a streamer by trade and the streaming bot I use for my streams can read INI files and trigger certain events during stream based on key values that are saved in INI files I have set up. Then it got me wondering, "If RPG Maker MZ had a plugin that could allow me to write to an INI file, my streams could become even more of a community game/adventure than they already are!" Since at that point I'd have a direct communicative Rosetta Stone (if you will) between RPG Maker, the streamer bot, and my community to go on even crazier immersive adventures of my design.
Any help to shed some light on this inquiry would be greatly appreciative. I'm not too well versed in programming nor RPG Maker MZ's inner workings, but I'm willing to learn if pointed in the right direction.
ANSWER FOR FUTURE CURIOUS MINDS:
JavaScript:
const fs = require('fs');
const iniContent ='[Test Section]\n' + 'Test Key = "1.000000"';
const filePath = "C:/RPG Maker Folder/Test.ini";
fs.writeFile(filePath, iniContent, (err) => {
if (err) {
console.error("Error writing file:", err);
return;
}
console.log("File written successfully!");
});
Please take note:
- The names "iniContent" and "filePath" are variable names, they can theoretically be named anything you want.
- The "writeFile" command will overwrite any and all data in the INI file and replace it with the variable "iniContent" so make sure that you are not having RPG Maker write to a well populated INI File.
- In my testing, and this might just be my inexperience, but I have found leaving out the Error catch "(err)" section of the "fs.writeFile" function will not successfully write your data to the INI File.
- When copying a file path from File Explorer the slashes will be in the wrong direction for js, you will have to manually change all the "\" to "/"
- To utilize this code above, simply copy and paste the above into a "Script" Command in RPG Maker MZ's Event Commands Menu.
- To do this first start by toggling to the Event editing mode. Find a tile and double click on it to open up the Event Editor window.
- Double click on a blank line within the "Contents" section.
- Find your way to page 3 in the "Event Commands" window and locate the section labeled "Advance" and click "Script"
- Finally copy/paste the above into the Script Window, edit the variables as needed and you should be good to go!