I'm back again with another INI related question. Since tinkering with Event Tiles being able to write to INI Files (Of which you can find here: https://forums.rpgmakerweb.com/inde...an-mz-event-tile-write-to-an-ini-file.178363/), I've been curious on the reverse: reading from INI Files and subsequently using that data in a Conditional Branch?
Answer for Future Curious Minds:
Please take note:
Niche Case Scenario:
If you are using something that is automatically writing to an INI file there is a chance it saves with a line break at the end of the INI file. In this situation the value comparison will be off as RPG Maker will be looking for "[Green]", but what you are giving it is "[Green]" with a line break. So they will not be the same. After some testing I have found a solution for this niche case scenario.
Additional Notes:
Answer for Future Curious Minds:
INI:
[Red]
JavaScript:
const fs = require('fs');
const filePath = "C:/RPG Maker Folder/Test.ini";
$gameVariables.setValue(1, fs.readFileSync(filePath));
JavaScript:
$gameVariables.value(1) == "[Green]"
Please take note:
- Within the $gameVariables.setValue function, the 1 is the variable number. RPG Maker uses numbers to store its variables rather than strings. The "1" above can be any number since it is just a variable.
- The second Javascript block is the Conditional Branch Script you will be using for the If/Else.
- The INI in the example above is "[Red]", where as the Conditional Branch is looking for [Green]. The result will be false since the 2 don't match up thus outputting the Else branch.
Niche Case Scenario:
If you are using something that is automatically writing to an INI file there is a chance it saves with a line break at the end of the INI file. In this situation the value comparison will be off as RPG Maker will be looking for "[Green]", but what you are giving it is "[Green]" with a line break. So they will not be the same. After some testing I have found a solution for this niche case scenario.
INI:
1: [Green]
2:
JavaScript:
const fs = require('fs');
const filePath = "C:/RPG Maker Folder/Test.ini";
const dataString = fs.readFileSync(filePath);
const newString = dataString.slice(0,-2);
$gameVariables.setValue(1, newString);
JavaScript:
$gameVariables.value(1) == "[Green]"
Additional Notes:
- I have included "1:" and "2:" in the INI code block just to illustrate there is a blank new line, where line 1 is "[Green]" and line 2 is a blank new line. "1:" and "2:" will not be present in the INI file.
- Slicing the last 2 characters from the dataString above will leave you with the "[Green]" you will be looking for when comparing the gameVariables.