Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var fs = require('fs');
- var path = require('path'); // Better for cross-platform paths
- var _folderData = parameters['Folder Data'] || '/data/srpg';
- let folderPath = process.cwd() + _folderData;//_folderData should be custom
- let fileOpen = path.join(folderPath, filename + ".json");
- try {
- // readFileSync stops the code execution until the file is ready
- let jsonString = fs.readFileSync(fileOpen, 'utf8');
- let jsObject = JSON.parse(jsonString);
- // Store it where the rest of the game can see it
- this._jsonData = jsObject;
- console.log("Data Loaded Successfully:", this._jsonData);
- return jsObject;
- } catch (err) {
- console.error("Failed to load JSON:", err);
- return null
- }
Advertisement
Add Comment
Please, Sign In to add comment