I have a javascript file which contains an array of objects. That array also contains some functions as objects. So keep in mind I can't use JSON parsing as it will return an error. Now I need to read that js file and access that array and add one more function as an object in that array and save it to a hard disk. Is there any parsing library which can help me with that and how?
Here is the js file
let notifications = {
"Welcome": {
title: "Welcome",
body: "",
icon: ""
}};
let script = {
"Start": [
"notify Welcome",
{
"Input": {
"Text": "What is your name?",
"Validation": function (input) {
return input.trim().length > 0;
},
"Save": function (input) {
storage.player.Name = input;
return true;
},
"Warning": "You must enter a name!"
}
},
"h Hi {{player.Name}} Welcome!",
"h Currently you have {{player.intelligence}} points of Intelligence but you seem far more intelligent, how about we add five points?",
{"Function":{
"Apply": function () {
storage.player.intelligence += 5;
return true;
},
"Reverse": function () {
storage.player.intelligence -= 5;
}
}},
"h There you have it, you now have {{player.intelligence}} points of Intelligence",
{
"Choice": {
"Dialog": "h Have you already read some documentation?",
"Yes": {
"Text": "Yes",
"Do": "jump Yes"
},
"No": {
"Text": "No",
"Do": "jump No"
}
}
}
],
"Yes": [
"h That's awesome!",
"h Then you are ready to go ahead and create an amazing Game!",
"h I can't wait to see what story you'll tell!",
"end"
],
"No": [
"h You can do it now.",
"display message Help",
"h Go ahead and create an amazing Game!",
"h I can't wait to see what story you'll tell!",
"end"
]};
Now I need to add some more choices in scripts array programmatically and save it.