MV Arrays in MV plugin HELP!!!

Hey there game makers!

So I I'm working on a plugin that contains an array, long story short the plugin has an array that can be changed with params and if the array contains another param it should do something and something else if it doesn't.

My problem is that it's doing what it should if false.

Here's my summerized code

JavaScript:
*@param 1
*@default String1
*
*@param 2
*@default String1, String2, String3, String4
*

var Imported = Imported || {};
Imported.PluginName = true;
var BDZparam = BDZparam || {};

BDZparam.parameters = PluginManager.parameters('PluginName');
BDZparam.Default = String(BDZ.parameters['Param 1'] || "String1");
BDZparam.Array = Object(BDZ.parameters['Param 2'] || "String2", "String2", "String3", "String4");

const myArray = [BDZparam.Array];
var arrayNo = myArray.length;

if(myarray.includes(String(BDZparam.Default))) {
  action 1
} else {
  action 2
}

My problem is that it's only doing action 2 whether or not the array contains the specified string.

Can anyone help?
In the includes, why are you passing your default through the String() function when your original declaration of it already made it be a string?

For that matter, why are you using the String() function in its declaration when the default format of all plugin parameters is a string?

Then, there's a misconception in your array declaration:
Code:
BDZ.parameters['Param 2']
is not a comma-delimited list of strings like you present in your OR. That is, it does not equal:
Code:
"String2", "String2", "String3", "String4"
(which, incidentally, has a typo) it equals
Code:
"String1, String2, String3, String4"

Finally, I think the root of your problem is:
Code:
const myArray = [BDZparam.Array];

I'm not sure why you're bothering to declare another variable equal to this, BDZparam.Array doesn't take up a lot of space to type or copy/paste. But you're encasing it in brackets, which means you're making the list of strings be one single element in myArray.

Therefore, includes() will only return true if you pass in another full object that has the full contents in the exact same format as the entirety of BDZparam.Array.

If you just did:
Code:
if (BGZparam.Array.includes(BGZparam.Default))
it should work as expected.
In addition to what Turan said...

Get rid of the Object constructor. You can convert a comma-delimited string to an array using the String#split method, e.g.
JavaScript:
"a,b,c,d".split(",");   // ["a", "b", "c", "d"]
Or you could use parameter @type string[] (introduced in MV v1.5.0), in which case you would parse it as JSON, e.g.
JavaScript:
JSON.parse(BDZ.parameters["1"]);
Also, note that as you've written it, the name of the parameters are just "1" and "2". @param is the directive, not part of the name.
Also, note that as you've written it, the name of the parameters are just "1" and "2".
Good call, I missed that part.
but another thing they didn't mention is the parameter call?

you call your parameters like this: (BDZ.parameters....)
while the plugin parameter should be this: (BDZparam.parameters.....)

those needs to be equal to function though 🙂
@ShadowDragon Also a good call!

No offense OP, but there was so much wrong it's hard for one person to get it all in a single pass 😅
In the includes, why are you passing your default through the String() function when your original declaration of it already made it be a string?

For that matter, why are you using the String() function in its declaration when the default format of all plugin parameters is a string?

Then, there's a misconception in your array declaration:
Code:
BDZ.parameters['Param 2']
is not a comma-delimited list of strings like you present in your OR. That is, it does not equal:
Code:
"String2", "String2", "String3", "String4"
(which, incidentally, has a typo) it equals
Code:
"String1, String2, String3, String4"

Finally, I think the root of your problem is:
Code:
const myArray = [BDZparam.Array];

I'm not sure why you're bothering to declare another variable equal to this, BDZparam.Array doesn't take up a lot of space to type or copy/paste. But you're encasing it in brackets, which means you're making the list of strings be one single element in myArray.

Therefore, includes() will only return true if you pass in another full object that has the full contents in the exact same format as the entirety of BDZparam.Array.

If you just did:
Code:
if (BGZparam.Array.includes(BGZparam.Default))
it should work as expected.
Thanks a lot for your help, the plugin is now working perfectly and as for me declaring another variable, I'm still new to javascript so I thought it was necessary.
but another thing they didn't mention is the parameter call?

you call your parameters like this: (BDZ.parameters....)
while the plugin parameter should be this: (BDZparam.parameters.....)

those needs to be equal to function though 🙂
That one was a typo on my part in the actual plugin they're all the same so it wasn't a problem.
as for me declaring another variable, I'm still new to javascript so I thought it was necessary.
You might want to work your way through some more basic tutorials before diving into something this advanced. Knowing what variables do and when they're needed is kinda fundamental stuff.

(general rule: you only need to declare a variable if you want to modify something's value without changing the original thing)

But I'm glad it's working! Good luck with your project.
You might want to work your way through some more basic tutorials before diving into something this advanced. Knowing what variables do and when they're needed is kinda fundamental stuff
Do you know where I can find some good tutorials?
A lot of stuff comes up if you Google it. I like the format and chunk-size of w3schools, starting with the Statements chapter.
A lot of stuff comes up if you Google it. I like the format and chunk-size of w3schools, starting with the Statements chapter.
Thanks a lot for this.

Original thread: https://forums.rpgmakerweb.com/threads/arrays-in-mv-plugin-help.160138/