MZ Help with JSON and JavaScript

Hey guys,

I'm a rank amateur when it comes to Javascript, but I'm slowly learning. I'm trying to create a Quest System. Basically its an array that will update as the player goes through the game.

this is what I have so far this is the JSON file.
Code:
[
null,
{"id":1,"name":"","description":"","iconIndex":0,"reward1":"","reward2":"","reward3":""}
]

this is the JS file

Code:
var $dataQuests = null;

DataManager._databaseFiles.push({
    name: '$dataQuests',
    src: 'Quest.json'
});

function QuestManager() {
    throw new Error('this is a static class');
};

QuestManager.data = function(id) {
    return $dataQuests[id];
};

So I want to end up having these display in a Picture Menu as the details of the quest. I may have to add more Items to the array as I go, but for now I'm just concentrating on how to add more lines to this. I've learned about the .push function but I'm not sure how to use that to update the JSON. Can anyone help?
The default JSON files for the database and maps are updated via the editor, not by the game as you play it. Usually any additional JSON files would be created in a text editor, as you've done.

Why do you want to have a push function and update the JSON?
The default JSON files for the database and maps are updated via the editor, not by the game as you play it. Usually any additional JSON files would be created in a text editor, as you've done.

Why do you want to have a push function and update the JSON?

I wanted the player to collect quests as they played. They may not be able to collect all quests due to circumstances, and some quests will change in how the player interacts with them. This way the player will only be in control of the ones they have received.

I thought it would be easier to just push the new details and quests vs assigning each one and their various ways they can change into variables.

So if that's not possible, it sounds like I need an array in the JS alone that will keep all of the quests. So my follow up question would be can I make an array inside of an array? I'll need the "outer" array to handle each quest. And the "inner" array to handle each detail about the quest. Or am I thinking in the wrong way here?

Extra details: I attempted to make an actual plugin with annotations that created each quest with details, but I couldn't figure out how to entirely call them within events. To make my broken system work, I figured I would use the Text picture plugin and Visutellas message core plugin. The latter would make text codes and the former would show them on screen.

Edit: was just googling around and found out about nested arrays.

So if I did something like this:

let quests = [];
quests[0] = let questDetails = ["name", " description", "rewards" ....]

And then used the push function to just add more to the array as the game is played would that be correct?
JSON files set up like this don't belong to a specific save file. If you start it off empty, then start a new game and push stuff to that file, if you save it, then start a new game, those quests will be available in the new game.

What I suggest you do here is create a static JSON file that has the details of all the quests that can be given, and that will use the functions you've already shown above. But to control what quests the player has received / completed in the active game, add an array or two to Game_Player. This means quests will be attached to that save file only and not impact other save files, and the player's progress with quests will automatically be included in save files.
JSON files set up like this don't belong to a specific save file. If you start it off empty, then start a new game and push stuff to that file, if you save it, then start a new game, those quests will be available in the new game.

What I suggest you do here is create a static JSON file that has the details of all the quests that can be given, and that will use the functions you've already shown above. But to control what quests the player has received / completed in the active game, add an array or two to Game_Player. This means quests will be attached to that save file only and not impact other save files, and the player's progress with quests will automatically be included in save files.
I edited my reply before I saw yours. That make sense now with the JSON file.

Like I originally stated I'm a rank amateur to JavaScript. Could you give me a basic example of what the correct syntax of adding an array to gameplayer would look like?

I am not asking you to build me a plugin, just trying to find the right direction to start experimenting with.

Thanks
You'd just need to alias the Game_P:layer.prototype.initMembers function and add your own variable in there:

this._currentQuests = []


Then you need to create functions to add quests, inquire on them, and remove them.

Take a look at Game_Actor, which uses arrays for skills.


You just need to save quest ids in this array, not the name, description, list of rewards. That stuff all comes from $dataQuests, just like all the nitty gritty stuff about skills comes from $dataSkills. The array on the actor just contains the skill ids.

This will keep your save file smaller, as you don't need to save all of those details with the save file.
You'd just need to alias the Game_P:layer.prototype.initMembers function and add your own variable in there:

this._currentQuests = []


Then you need to create functions to add quests, inquire on them, and remove them.

Take a look at Game_Actor, which uses arrays for skills and equipment.
Ok so it would be similar to the .hasItem .gainItem .loseItem functions in Rpgmaker. But instead it would be .hasQuest .gainQuest .loseQuest

The only thing I don't fully understand is the "alias" term.
Why don't you try to use hashmaps? I think javascript doesn't have hashmaps by default, but basically you can create the equivalent of hashmaps in javascript.

A hashmap is basically a type of data structure that allows you to associate a value to a key, the value can be a primitive(numbers, boolean values, characters, strings) or an object(arrays, objects, lists), and the key can be a number or a keyword, you can have as much keywords linked to a value as you want. Also, saving hashmaps or hashsets to jsons is pretty common and should be easy to add to the save file.

My only issue with using hashmaps or hashsets in javascript is that, I feel (i might be wrong, and if I am, please let me know) that javascript can't handle huge hashmaps or hashsets, and also, because the way the code is written for RPG Maker, might cause issues.
Why don't you try to use hashmaps? I think javascript doesn't have hashmaps by default, but basically you can create the equivalent of hashmaps in javascript.

A hashmap is basically a type of data structure that allows you to associate a value to a key, the value can be a primitive(numbers, boolean values, characters, strings) or an object(arrays, objects, lists), and the key can be a number or a keyword, you can have as much keywords linked to a value as you want. Also, saving hashmaps or hashsets to jsons is pretty common and should be easy to add to the save file.

My only issue with using hashmaps or hashsets in javascript is that, I feel (i might be wrong, and if I am, please let me know) that javascript can't handle huge hashmaps or hashsets, and also, because the way the code is written for RPG Maker, might cause issues.
If I had more knowledge on JavaScript I might be able to decipher what you just said, but I think I got half of it lol.

The way shaz had been directing me has been an actual godsend honestly. I don't want to shoot your idea down but I don't think I'm proficient enough to figure out how to make that yet.

I do appreciate the reply though and if I ever need help with hashmaps I'll be sure to hit you up for more information!
If I had more knowledge on JavaScript I might be able to decipher what you just said, but I think I got half of it lol.

The way shaz had been directing me has been an actual godsend honestly. I don't want to shoot your idea down but I don't think I'm proficient enough to figure out how to make that yet.

I do appreciate the reply though and if I ever need help with hashmaps I'll be sure to hit you up for more information!
Oh, don't worry, I'm also not that proficient in javascript, but I can manage my way of doing stuff (god bless stackoverflow).
I once made a script to create multiple bags of items, and the way I did it back then was with hashmaps, so creating a quest log would be the same basic idea, but instead of items, you have events, switches and variables, which already are arrays.

So, if you feel json files suit better your idea, go ahead, but I think that is only half of the puzzle.

Oh, by the way. Alias in lamest terms, is a way to add or remove functionality to an existing method without "rewriting" (technically you can rewrite but I'll get to that) the original method.

For example, lets supose you have the following method

method foo() {
some code
}

but you want it to do something else other than the original, so you do the following

other_foo = foo;
method foo() {
other_foo.call(this) <-- This basically executes the original method, can be at the begining or the end.
more code <-- This is basically the other stuff you need the orignal method to do
}

While aliasing is convenient in some circumstances, in some others it is much more easier to just rewrite the original method, but it might cause compatibility issues. It will all depends on how the method is written.
Oh, don't worry, I'm also not that proficient in javascript, but I can manage my way of doing stuff (god bless stackoverflow).
I once made a script to create multiple bags of items, and the way I did it back then was with hashmaps, so creating a quest log would be the same basic idea, but instead of items, you have events, switches and variables, which already are arrays.

So, if you feel json files suit better your idea, go ahead, but I think that is only half of the puzzle.

Oh, by the way. Alias in lamest terms, is a way to add or remove functionality to an existing method without "rewriting" (technically you can rewrite but I'll get to that) the original method.

For example, lets supose you have the following method

method foo() {
some code
}

but you want it to do something else other than the original, so you do the following

other_foo = foo;
method foo() {
other_foo.call(this) <-- This basically executes the original method, can be at the begining or the end.
more code <-- This is basically the other stuff you need the orignal method to do
}

While aliasing is convenient in some circumstances, in some others it is much more easier to just rewrite the original method, but it might cause compatibility issues. It will all depends on how the method is written.
Sorry, fell asleep.

I don't fully understand with your example.
This is the code I need to Alias to add my own Array into it.

Code:
Game_Actor.prototype.initMembers = function() {
    Game_Battler.prototype.initMembers.call(this);
    this._actorId = 0;
    this._name = "";
    this._nickname = "";
    this._classId = 0;
    this._level = 0;
    this._characterName = "";
    this._characterIndex = 0;
    this._faceName = "";
    this._faceIndex = 0;
    this._battlerName = "";
    this._exp = {};
    this._skills = [];
    this._equips = [];
    this._actionInputIndex = 0;
    this._lastMenuSkill = new Game_Item();
    this._lastBattleSkill = new Game_Item();
    this._lastCommandSymbol = "";
};

If I do what you've suggested it would look like this:

Code:
Other_Game_Actor = Game_Actor;

Game_Actor.prototype.initMembers = function() {
    Other_Game_Actor.call(this)
    this._quests = [];
    
};

I may be wrong, but it just doesn't look correct. Or maybe I'm not following your directions the right way.
Why don't you try to use hashmaps? I think javascript doesn't have hashmaps by default, but basically you can create the equivalent of hashmaps in javascript.

A hashmap is basically a type of data structure that allows you to associate a value to a key, the value can be a primitive(numbers, boolean values, characters, strings) or an object(arrays, objects, lists), and the key can be a number or a keyword, you can have as much keywords linked to a value as you want. Also, saving hashmaps or hashsets to jsons is pretty common and should be easy to add to the save file.

My only issue with using hashmaps or hashsets in javascript is that, I feel (i might be wrong, and if I am, please let me know) that javascript can't handle huge hashmaps or hashsets, and also, because the way the code is written for RPG Maker, might cause issues.
Javascript can do hashmaps by default; it's basically an array where the keys are strings/objects rather than indexes.
Sorry, fell asleep.

I don't fully understand with your example.
This is the code I need to Alias to add my own Array into it.

Code:
Game_Actor.prototype.initMembers = function() {
    Game_Battler.prototype.initMembers.call(this);
    this._actorId = 0;
    this._name = "";
    this._nickname = "";
    this._classId = 0;
    this._level = 0;
    this._characterName = "";
    this._characterIndex = 0;
    this._faceName = "";
    this._faceIndex = 0;
    this._battlerName = "";
    this._exp = {};
    this._skills = [];
    this._equips = [];
    this._actionInputIndex = 0;
    this._lastMenuSkill = new Game_Item();
    this._lastBattleSkill = new Game_Item();
    this._lastCommandSymbol = "";
};

If I do what you've suggested it would look like this:

Code:
Other_Game_Actor = Game_Actor;

Game_Actor.prototype.initMembers = function() {
    Other_Game_Actor.call(this)
    this._quests = [];
   
};

I may be wrong, but it just doesn't look correct. Or maybe I'm not following your directions the right way.
Ok, I'll give you an example with a different method in a different class, it works the same

This is how Scene_Map.prototype.start function is written by default in the code
JavaScript:
Scene_Map.prototype.start = function() {
    Scene_Message.prototype.start.call(this);
    SceneManager.clearStack();
    if (this._transfer) {
        this.fadeInForTransfer();
        this.onTransferEnd();
    } else if (this.needsFadeIn()) {
        this.startFadeIn(this.fadeSpeed(), false);
    }
    this.menuCalling = false;
};
Now lets add some code to make it so, based on some configuration by the user, the map scene goes full screen but without rewriting the method, we'll use aliasing. Let's do something like this.

JavaScript:
const Winshifter_Scene_Map_start = Scene_Map.prototype.start;
Scene_Map.prototype.start = function() {
    Winshifter_Scene_Map_start.apply(this, arguments);
    if (Winshifter.isFullScreenOnStart && !Graphics._isFullScreen()) {
        Graphics._switchFullScreen();
        Graphics._updateAllElements();
    }
};

Let's break it into parts so it can be understandable.

const Winshifter_Scene_Map_start = Scene_Map.prototype.start;<-- This is basically a new "variable" (technically not, but for informative sakes, let's calle it a variable). This will be needed because we want to call the original method as it was written at some point in the code.

Scene_Map.prototype.start = function() <-- Inmediatly after the const, you need to basically copy the original method like here, this is part of the rules, so take it as it is.

Winshifter_Scene_Map_start.apply(this, arguments); <--This basically is telling javascript that we want the original code to be executed, this is how it is done for IE6, but you can also use the older vertions of it, which will be Winshifter_Scene_Map_start.call(this);, both work the same.

if (Winshifter.isFullScreenOnStart && !Graphics._isFullScreen()) {
Graphics._switchFullScreen();
Graphics._updateAllElements();
}
Above is the part that I added to the original method.

Aliasing will make javascript to think the code works this way.

JavaScript:
Scene_Map.prototype.start = function() {
    Scene_Message.prototype.start.call(this);
    SceneManager.clearStack();
    if (this._transfer) {
        this.fadeInForTransfer();
        this.onTransferEnd();
    } else if (this.needsFadeIn()) {
        this.startFadeIn(this.fadeSpeed(), false);
    }
    this.menuCalling = false;
    if (Winshifter.isFullScreenOnStart && !Graphics._isFullScreen()) {
        Graphics._switchFullScreen();
        Graphics._updateAllElements();
    }
};

I hope this example gives you an idea how Aliasing works, it allows you to basically "inject" code into an existing code on a separate file.

Let me know if you have further questions.
You'd just need to alias the Game_P:layer.prototype.initMembers function and add your own variable in there:

this._currentQuests = []


Then you need to create functions to add quests, inquire on them, and remove them.

Take a look at Game_Actor, which uses arrays for skills.


You just need to save quest ids in this array, not the name, description, list of rewards. That stuff all comes from $dataQuests, just like all the nitty gritty stuff about skills comes from $dataSkills. The array on the actor just contains the skill ids.

This will keep your save file smaller, as you don't need to save all of those details with the save file.

Ok, I'll give you an example with a different method in a different class, it works the same

This is how Scene_Map.prototype.start function is written by default in the code
JavaScript:
Scene_Map.prototype.start = function() {
    Scene_Message.prototype.start.call(this);
    SceneManager.clearStack();
    if (this._transfer) {
        this.fadeInForTransfer();
        this.onTransferEnd();
    } else if (this.needsFadeIn()) {
        this.startFadeIn(this.fadeSpeed(), false);
    }
    this.menuCalling = false;
};
Now lets add some code to make it so, based on some configuration by the user, the map scene goes full screen but without rewriting the method, we'll use aliasing. Let's do something like this.

JavaScript:
const Winshifter_Scene_Map_start = Scene_Map.prototype.start;
Scene_Map.prototype.start = function() {
    Winshifter_Scene_Map_start.apply(this, arguments);
    if (Winshifter.isFullScreenOnStart && !Graphics._isFullScreen()) {
        Graphics._switchFullScreen();
        Graphics._updateAllElements();
    }
};

Let's break it into parts so it can be understandable.

const Winshifter_Scene_Map_start = Scene_Map.prototype.start;<-- This is basically a new "variable" (technically not, but for informative sakes, let's calle it a variable). This will be needed because we want to call the original method as it was written at some point in the code.

Scene_Map.prototype.start = function() <-- Inmediatly after the const, you need to basically copy the original method like here, this is part of the rules, so take it as it is.

Winshifter_Scene_Map_start.apply(this, arguments); <--This basically is telling javascript that we want the original code to be executed, this is how it is done for IE6, but you can also use the older vertions of it, which will be Winshifter_Scene_Map_start.call(this);, both work the same.

if (Winshifter.isFullScreenOnStart && !Graphics._isFullScreen()) {
Graphics._switchFullScreen();
Graphics._updateAllElements();
}
Above is the part that I added to the original method.

Aliasing will make javascript to think the code works this way.

JavaScript:
Scene_Map.prototype.start = function() {
    Scene_Message.prototype.start.call(this);
    SceneManager.clearStack();
    if (this._transfer) {
        this.fadeInForTransfer();
        this.onTransferEnd();
    } else if (this.needsFadeIn()) {
        this.startFadeIn(this.fadeSpeed(), false);
    }
    this.menuCalling = false;
    if (Winshifter.isFullScreenOnStart && !Graphics._isFullScreen()) {
        Graphics._switchFullScreen();
        Graphics._updateAllElements();
    }
};

I hope this example gives you an idea how Aliasing works, it allows you to basically "inject" code into an existing code on a separate file.

Let me know if you have further questions.
Hey,

So after ALOT of testing and trying I've got it working....
I may have done it in a way most people would say not to do, but I edited the Managers and Objects files directly. I added new functions that mimic the Item functions but just called it Quests instead. Scriptcalls are working and I'm actually really happy with how its shaping up.

Since I've solved my problem I'm guessing this thread can be closed.

However if its alright to ask another question, if not i'll make a new thread.

Does anyone know how to make a code that will check an array, and only display the first 8 true responses?

Example:
Array = [true, true, false, false, false, true, true, true, true, true, false, true]

I know I can just check each one individually but was hoping to have something that made use of IF ELSE statements...

I'm using this to make a picture menu. I'll be using the Text picture plugin alongside the button picture plugin for MZ that will make clickable pictures. With my current layout of the menu, I'll only have the room to display 8 Names of quests at a time. I figured I could just turn a switch on to show the next 8 and so on to simulate a page turn in the names.

Just throwing out ideas, not sure if they'll work but maybe I can assign the ID of each true response to a variable?

like:
if $gameParty.hasQuest($dataQuests[ID]) {
$gameVariables.setValue(1, ID)
} else if {
etc...

but I can already see that example not working because it'll try to assign everything to the same variable over and over. I hope I'm making sense here.
Hey,

So after ALOT of testing and trying I've got it working....
I may have done it in a way most people would say not to do, but I edited the Managers and Objects files directly. I added new functions that mimic the Item functions but just called it Quests instead. Scriptcalls are working and I'm actually really happy with how its shaping up.
Good that it worked but........
don't....
don't...
absolutely don't do that. Don't write the default files, it's the equivalent of commiting suicide in codint (ok, I exagerate). Simply create a different file and make it a plugin, I think there is even a template to create plugins here in the forums.

Does anyone know how to make a code that will check an array, and only display the first 8 true responses?

Example:
Array = [true, true, false, false, false, true, true, true, true, true, false, true]

I know I can just check each one individually but was hoping to have something that made use of IF ELSE statements...

I'm using this to make a picture menu. I'll be using the Text picture plugin alongside the button picture plugin for MZ that will make clickable pictures. With my current layout of the menu, I'll only have the room to display 8 Names of quests at a time. I figured I could just turn a switch on to show the next 8 and so on to simulate a page turn in the names.

Just throwing out ideas, not sure if they'll work but maybe I can assign the ID of each true response to a variable?

like:
if $gameParty.hasQuest($dataQuests[ID]) {
$gameVariables.setValue(1, ID)
} else if {
etc...

but I can already see that example not working because it'll try to assign everything to the same variable over and over. I hope I'm making sense here.
Well, I have certain questions about it. Does the array always have more than 8 items, regardless of value? What type of data structure(array,list, object) it has to return?

Since I'm not really sure of some things I'll just give you an example from the little information you give me

JavaScript:
let maxItems = 8;
let currItem = 1;
let retArray = [];
for (let i = 0; i < array.lenght; i++) {
    if (array[i]) {
        if (currItem <= maxItems) {
            retArray.push(i);
            currItem++;
        } else {
            break;
        }
    }
}

don't take that code for granted, it's not tested but at least it should give you an idea.
Good that it worked but........
don't....
don't...
absolutely don't do that. Don't write the default files, it's the equivalent of commiting suicide in codint (ok, I exagerate). Simply create a different file and make it a plugin, I think there is even a template to create plugins here in the forums.


Well, I have certain questions about it. Does the array always have more than 8 items, regardless of value? What type of data structure(array,list, object) it has to return?

Since I'm not really sure of some things I'll just give you an example from the little information you give me

JavaScript:
let maxItems = 8;
let currItem = 1;
let retArray = [];
for (let i = 0; i < array.lenght; i++) {
    if (array[i]) {
        if (currItem <= maxItems) {
            retArray.push(i);
            currItem++;
        } else {
            break;
        }
    }
}

don't take that code for granted, it's not tested but at least it should give you an idea.

Hey thanks for trying so hard for me!
I'm not going to lie, I don't know what half of the terms in your code mean.

So the JSON file is still the same as what I typed at the beginning of the post.

These are the functions I added into Manager:
Code:
$dataQuests = null;

DataManager._databaseFiles = [
    { name: "$dataActors", src: "Actors.json" },
    { name: "$dataClasses", src: "Classes.json" },
    { name: "$dataSkills", src: "Skills.json" },
    { name: "$dataItems", src: "Items.json" },
    { name: "$dataWeapons", src: "Weapons.json" },
    { name: "$dataArmors", src: "Armors.json" },
    { name: "$dataEnemies", src: "Enemies.json" },
    { name: "$dataTroops", src: "Troops.json" },
    { name: "$dataStates", src: "States.json" },
    { name: "$dataAnimations", src: "Animations.json" },
    { name: "$dataTilesets", src: "Tilesets.json" },
    { name: "$dataCommonEvents", src: "CommonEvents.json" },
    { name: "$dataSystem", src: "System.json" },
    { name: "$dataMapInfos", src: "MapInfos.json" },
    { name: "$dataQuests", src: "Quest.json"} // this Line has been added
];

DataManager.isQuest = function(item) {
    return item && $dataQuests.includes(item);
};

This is what was added into Objects:
Code:
Game_Item.prototype.isQuest = function() {
    return this._dataClass === "quest";
};

Game_Item.prototype.object = function() {
    if (this.isSkill()) {
        return $dataSkills[this._itemId];
    } else if (this.isItem()) {
        return $dataItems[this._itemId];
    } else if (this.isWeapon()) {
        return $dataWeapons[this._itemId];
    } else if (this.isArmor()) {
        return $dataArmors[this._itemId];
    } else if (this.isQuest()) { // this Line is added
        return $dataQuests[this._itemId];
    } else {
        return null;
    }
};

Game_Item.prototype.setObject = function(item) {
    if (DataManager.isSkill(item)) {
        this._dataClass = "skill";
    } else if (DataManager.isItem(item)) {
        this._dataClass = "item";
    } else if (DataManager.isWeapon(item)) {
        this._dataClass = "weapon";
    } else if (DataManager.isArmor(item)) {
        this._dataClass = "armor";
    } else if (DataManager.isQuest(item)) { // this line is added
        this._dataClass = "quest";
    } else {
        this._dataClass = "";
    }
    this._itemId = item ? item.id : 0;
};

Game_Party.prototype.initialize = function() {
    Game_Unit.prototype.initialize.call(this);
    this._gold = 0;
    this._steps = 0;
    this._lastItem = new Game_Item();
    this._menuActorId = 0;
    this._targetActorId = 0;
    this._actors = [];
    this.initAllItems();
    this.initAllQuests(); // this line is added
};

Game_Party.prototype.initAllQuests = function() {
    this._quests = {}; // I think this is the Line for the arrays data I need.
};

Game_Party.prototype.quests = function() {
    return Object.keys(this._quests).map(id => $dataQuests[id]);
};

Game_Party.prototype.questContainer = function(item) {
    if (!item) {
        return null;
    } else if (DataManager.isQuest(item)) {
        return this._quests;
    } else {
        return null;
    }
};

Game_Party.prototype.numQuests = function(item) {
    const qcontainer = this.questContainer(item);
    return qcontainer ? qcontainer[item.id] || 0 : 0;
};

Game_Party.prototype.maxQuests = function(/*item*/) {
    return 1;
};

Game_Party.prototype.hasMaxQuests = function(items) {
    return this.numQuests(item) >= this.maxQuests(item);
};

Game_Party.prototype.hasQuest = function(item) {
    if (this.numQuests(item) > 0) {
        return true;
    } else {
        return false
    }
};

Game_Party.prototype.gainQuest = function(item, amount) {
    const qcontainer = this.questContainer(item);
    if (qcontainer) {
        const lastNumber = this.numQuests(item);
        const newNumber = lastNumber + amount;
        qcontainer[item.id] = newNumber.clamp(0, this.maxQuests(item));
        if (qcontainer[item.id] === 0) {
            delete qcontainer[item.id];
        }
        $gameMap.requestRefresh();
    }
};

Game_Party.prototype.loseQuest = function(item, amount) {
    this.gainQuest(item, -amount);
};

So if you compare my new code to the "items" in the original code its almost identical except for things are named quest instead of item.

So quests will work almost the same way except you cannot physically see them anywhere in game, hence the picture menu.

$dataQuests .id .description .iconIndex .reward1 .reward2 .reward3
$gameParty ._quest .hasQuest .gainQuest .loseQuest all work in a script call.

To test out the scriptcalls, I put them into a Control Variable in the script portion, then had it show me a text message using the text code \V[id].

So I used $gameParty.gainQuest($dataQuests[1], 1); // I left an amount in the code just incase i wanted to play with that later.

and then turned on a selfswitch in the event and had controlVariables1 = $gameParty.hasQuest($dataQuest[1]);
and it brought up a message that says true.

I also showed a message before I had received the quest just to test and it pulled up 0. I'm guessing it doesnt recognize if its False because it was set up to say false.

There can be a various amount of quests in the array at anytime. there could be 0 or there could be 100. It will depend on the player picking up the quests by talking to NPC's.

I hope this is more information that will explain how its all working right now.
When an issue is resolved, please use the Report button to report your post so the thread can be closed. New, unrelated questions should go into new threads.

It would be better for you to create a plugin that aliases those methods and adds the extra stuff than to change the core files directly. Doing it your way means if you ever get an update of the engine or the core files and you want to update your project, you have to remember all the changes you made and redo them, and if you forget anything or you make a mistake when you redo them, it will no longer work.
When an issue is resolved, please use the Report button to report your post so the thread can be closed. New, unrelated questions should go into new threads.

It would be better for you to create a plugin that aliases those methods and adds the extra stuff than to change the core files directly. Doing it your way means if you ever get an update of the engine or the core files and you want to update your project, you have to remember all the changes you made and redo them, and if you forget anything or you make a mistake when you redo them, it will no longer work.

Ok, I will definitely work on converting this to a plugin. I wasn't thinking about updates when I was adding stuff lol.

But for anyone coming here to learn something or poke fun at my awful javascript! Its at a pretty solved area! With the changes I posted above, I ended up doing a healthy dose of scripting inside the editor.
I had to basically call the JSON line by line. when I'm done this script box will be much longer with all of the Quests in my game. (is this Optimal? no, but I'll work on my scripting abilities to get it shorter)
For some reason I can't get IF ELSE statements to work inside the editors Script box, so I'm just eventing the IF ELSE.

This is in a parallel process that only turns on when a Switch is hit. The switch is tied to a ButtonPicture from the plugin that comes with MZ.

If Control Switches 1 = ON
Code:
const currentQuest = []
currentQuest[0] = $gameParty.hasQuest($dataQuests[0]);
currentQuest[1] = $gameParty.hasQuest($dataQuests[1]);
currentQuest[2] = $gameParty.hasQuest($dataQuests[2]);
currentQuest[3] = $gameParty.hasQuest($dataQuests[3]);
currentQuest[4] = $gameParty.hasQuest($dataQuests[4]);
currentQuest[5] = $gameParty.hasQuest($dataQuests[5]);
currentQuest[6] = $gameParty.hasQuest($dataQuests[6]);
currentQuest[7] = $gameParty.hasQuest($dataQuests[7]);
currentQuest[8] = $gameParty.hasQuest($dataQuests[8]);

currentQuest.toString();

var currentQuest1 = [] // this code snippet will only grab the items from currentQuest array that are 
                                      // TRUE, for some odd reason anything not true will show up as 0.
currentQuest.forEach((val, index) => {
    if(val){
        currentQuest1.push(index);
    }
});

currentQuest1.toString();

$gameVariables.setValue(1, $dataQuests[currentQuest1[0]]);
$gameVariables.setValue(2, $dataQuests[currentQuest1[1]]);
$gameVariables.setValue(3, $dataQuests[currentQuest1[2]]);
$gameVariables.setValue(4, $dataQuests[currentQuest1[3]]);
$gameVariables.setValue(5, $dataQuests[currentQuest1[4]]);
$gameVariables.setValue(6, $dataQuests[currentQuest1[5]]);
$gameVariables.setValue(7, $dataQuests[currentQuest1[6]]);
$gameVariables.setValue(8, $dataQuests[currentQuest1[7]]);

From this point you could make another IF Switch 2 is ON and then where it says currentQuest1[ID] change the ID to the next set you want to show. Currently I can only show 8 Quests at a time due to how I have my menu set up, but ideally you could make as many $gameVariables as you wanted to fit it all in. So my next set will be currentQuest1[8] and upwards.

After this I had to call more Control Variables with this as its code:
Code:
$gameVariables.value(1).name
this would be control variable #9 for me. this number will change depending on how many Variables you want to change on the screen.

after that it was just calling the TextPicture Plugin. Using \V[9] and having the picture show up where I wanted it to. Keep in mind this only will display the name, you will have to make more Variables for the Description, rewards, and whatever else you placed in your Json File. You will not need to make Variables for Each quest, If you set yours up similar to mine with the initial 8, you will need the First 8, the NAME 8, the DESCRIPTION 8, ETC...

Again I will attempt to turn this into a functional Plugin. If I do end up making it, It will be free for anyone that wants to tinker with it. (seeing as most of the code is just a rewrite of the original code I can't really claim credit for any of it!)

Ok I've rambled enough. Thank you everyone for the help and advice that was thrown my way! It was a great help!

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/help-with-json-and-javascript.140331/