Hello, I'm new to js and I'm trying to figure out parameters and using arrays inside them.
The idea is that the plugin hides sealed skill types from the user during a battle. I got the basic functionality working but I decided to try to extend it by checking if the skill type ID is contained within an array modified by the exposed parameter.
When trying to edit the paramter in the visual mode it says that the parameter is "malformed" too.
What am I doing wrong?
EDIT:
I have won a victory today against this silly language.
So the problem I was having is that the skill types are stored as numbers and despite the parameters taking in what look like numbers, they were actually "Arrays of elements" that the computer assumed were letters. This meant that when I was comparing the skilltypes against the parameters that I was actually searching an array of characters looking for a number. So I looked online and found a way of converting the letters into numbers.
Then there may have been a problem with array.include which may be comparing against the position in memory instead of the value so that came out and was replaced with array.indexOf. Not too sure about that one, whatever this works now.
The number[] typing became string[] typing:
Converting the strings to numbers:
Searching the array:
Thanks for the help.
The idea is that the plugin hides sealed skill types from the user during a battle. I got the basic functionality working but I decided to try to extend it by checking if the skill type ID is contained within an array modified by the exposed parameter.
When trying to edit the paramter in the visual mode it says that the parameter is "malformed" too.
JavaScript:
/*
*@plugindesc Hides sealed skill types during battle.
*@author SirRule
*@param SkillTypeIDs
*@desc Only these skill types with these IDs will be affected. Leave blank for all.
*@type number[]
*@default 3,0
*/
(function () {
var parameters = PluginManager.parameters('HideSealedActions');
var paramArray = parameters['SkillTypeIDs'].split(',');
var _Window_ActorCommand_BuildSkillCommandWindow = Window_ActorCommand.prototype.addSkillCommands;
var _WIndow_ActorCommand_ModifyAttackCommand = Window_ActorCommand.prototype.addAttackCommand;
Window_ActorCommand.prototype.addSkillCommands = function () {
var skillTypes = this._actor.addedSkillTypes().filter(function (stypeId) {
if (!paramArray.includes(stypeId)) { return true; }
return !this._actor.isSkillTypeSealed(stypeId);
}, this);
skillTypes.sort(function (a, b) {
return a - b;
});
skillTypes.forEach(function (stypeId) {
var name = $dataSystem.skillTypes[stypeId];
this.addCommand(name, 'skill', true, stypeId);
}, this);
};
What am I doing wrong?
EDIT:
I have won a victory today against this silly language.
So the problem I was having is that the skill types are stored as numbers and despite the parameters taking in what look like numbers, they were actually "Arrays of elements" that the computer assumed were letters. This meant that when I was comparing the skilltypes against the parameters that I was actually searching an array of characters looking for a number. So I looked online and found a way of converting the letters into numbers.
Then there may have been a problem with array.include which may be comparing against the position in memory instead of the value so that came out and was replaced with array.indexOf. Not too sure about that one, whatever this works now.
The number[] typing became string[] typing:
JavaScript:
*@type string[]
*@default ["4"]
Converting the strings to numbers:
JavaScript:
var parameters = PluginManager.parameters('HideSealedActions');
var paramArray = JSON.parse(parameters['SkillTypeIDs']);
var numArray = [];
paramArray.forEach(ele => numArray.push(+ele));
Searching the array:
JavaScript:
var skillTypes = this._actor.addedSkillTypes().filter(function (stypeId) {
if (numArray.indexOf(stypeId) != -1) {
return !this._actor.isSkillTypeSealed(stypeId);
}
return true;
}, this);
Thanks for the help.