Plugin parameters

Hello again!! 😀

I'm trying to implement a parameter for my plugin:

* @param Menu Help Windows
* @type note[]
* @Default []

So, based on the commandwindow index, it will be show something in the help window i made for menu.


i'v already tried to do this in two ways, but in the final, i get the same error.

Here is the config of parameters in game:
Spoiler: parameters in game
ShgGOHV.png

but i keep get this error:
Spoiler: error
V1dXX4G.png

i've searched a lot in google, and i found the most answers is because the code trying to pass undefined to JSON.parse as an argument.
I try several things to fix, but none of them worked =/

the problem always happen when i go to a command where i not define any help text.
In the picture above, i have defined help text for the two first commands of menu. But in third i add nothing. then when i go to to him the error shows.

Here the code:
Code:
* @param Menu Help Windows
 * @type note[]
 * @default []
 *
 *
 */

 
var Imported = Imported || {}; //import namespace
Imported.Eli_HelpWindowsStruct = true;

var Eli = Eli || {}; //author namespace
Eli.HelpWindowsStruct = Eli.HelpWindowsStruct || {}; //plugin namespace

'use strict';

Eli.Parameters = PluginManager.parameters('Eli_HelpWindowsStruct');
    Eli.Param = Eli.Param || {};

Eli.Param.HelpWindowsStruct = {

    MenuHelpText: JSON.parse(Eli.Parameters['Menu Help Windows'])
};
    // CODE
    
    //SCENE MENU HELP - 955
    var Eli_Scene_Menu_create = Scene_Menu.prototype.create;
        Scene_Menu.prototype.create = function() {
            Eli_Scene_Menu_create.call(this);
                this.createHelpWindow();
        };

    Scene_Menu.prototype.createHelpWindow = function() {
        this._helpWindow = new Window_Help();
        this.addWindow(this._helpWindow);
        this._helpWindow.y = this._commandWindow.height;//324;
        this._helpWindow.x = 0;
        this._helpWindow.width = this._commandWindow.width;//730;
        this._helpWindow.height = Graphics.boxHeight - (this._commandWindow.height + this._goldWindow.height); 
    };
    
        var Eli_Scene_Menu_update = Scene_Menu.prototype.update;
        Scene_Menu.prototype.update = function() {
            Scene_MenuBase.prototype.update.call(this);
                this._helpWindow.setText(JSON.parse(Eli.Param.HelpWindowsStruct.MenuHelpText[this._commandWindow._index]));
        };
You can't JSON.parse an "array". You have to split the arguments in the parameter to make an array from there.
I believe note types need parsing twice because of the newlines. 😅

Might make things neater if you apply the parses when the param is fetched from the Plugin Manager, too, e.g.
Code:
JSON.parse(Eli.Parameters['Menu Help Windows'] || '[]').map(JSON.parse).map(JSON.parse);
Then you can simply use the parsed parameter in setText. 🙂
Code:
this._helpWindow.setText(Eli.Param.HelpWindowsStruct.MenuHelpText[this._commandWindow._index]);

Edit @Eliaquim: also looks like your plugin's got a 2 at the end of its filename in that error message, which means its parameters aren't recognised.
Ok people! I will try again.
@caethyril yeah i see the "2" in the final. Already fix that. 🙂
I will try this thing of json.parse that you talked in parameters. But i dont get the ".map" at first hauahauhaya but i will try and return!

@Poryg i will try finding a plugin for me to see as an example ^^
I will try this thing of json.parse that you talked in parameters. But i dont get the ".map" at first hauahauhaya but i will try and return!
Array.map is just a shorthand for "apply this function to each element of the array". 🙂
It's actually not an array though, it's an "array". It's a string that begins with [ and ends with ]. And it will always crash when you try to JSON.parse it.
It's actually not an array though, it's an "array". It's a string that begins with [ and ends with ]. And it will always crash when you try to JSON.parse it.
JSON.parse is, among other things, intended to convert string representations to objects/arrays, right? Or am I missing something? 😅
- https://developer.mozilla.org/en-US.../Global_Objects/JSON/parse#Using_JSON.parse()
Elia is using the param array notation introduced in v1.5.0: thread link~

For example, I've used this line in my own plugin with no adverse effects:
Code:
_.regions = JSON.parse(_.params['Target Regions'] || '[]').map(Number);
Hello!
@caethyril , your method worked and I did not receive the error by leaving unfilled fields. However, when I went to the Item scene, it gave me another error of not finding the index of the command window. = / When i try that again, i dont know why but give me another error =/
Spoiler: code
Code:
 * @param Menu Help Windows
 * @type note[]
 * @desc
 * @default []
 *
 * @param Item Category Help Windows
 * @type note[]
 * @desc
 * @default []
 
 var Imported = Imported || {}; //import namespace
Imported.Eli_HelpWindowsStruct = true;

var Eli = Eli || {}; //author namespace
Eli.HelpWindowsStruct = Eli.HelpWindowsStruct || {};

    'use strict';
   
Eli.Param.HelpWindowsStruct = {
 
     MenuHelpText: JSON.parse(Eli.Parameters['Menu Help Windows'] || '[]').map(JSON.parse).map(JSON.parse)
    ItemCategoryHelpText: JSON.parse(Eli.Parameters['Item Category Help Windows'] || '[]').map(JSON.parse).map(JSON.parse)
 };
 
 var EliHelp_Scene_Menu_create = Scene_Menu.prototype.create;
        Scene_Menu.prototype.create = function() {
            EliHelp_Scene_Menu_create.call(this);
                this.createHelpWindow();
        };

   
    Scene_Menu.prototype.createHelpWindow = function() {
        this._helpWindow = new Window_Help();
        this.addWindow(this._helpWindow);
        this._helpWindow.y = this._commandWindow.height;//324;
        this._helpWindow.x = 0;
        this._helpWindow.width = this._commandWindow.width;//730;
        this._helpWindow.height = Graphics.boxHeight - (this._commandWindow.height + this._goldWindow.height);
    };
   
    var EliHelp_Scene_Menu_update = Scene_Menu.prototype.update;
        Scene_Menu.prototype.update = function() {
            Scene_MenuBase.prototype.update.call(this);
                this._helpWindow.setText(Eli.Param.HelpWindowsStruct.MenuHelpText[this._commandWindow._index]);
        };
       
    Scene_Item.prototype.update = function() {
        Scene_MenuBase.prototype.update.call(this);
            if (this._categoryWindow.active) {
                this._helpWindow.setText(Eli.Param.HelpWindowsStruct.ItemCategoryHelpText[this._commandWindow._index]);
            }
    };

@Poryg , your method also worked, but the error persisted. Although also, I do not know if I have managed to actually do it right. But the same error of index in the item scene happens. I also try to learn something with the Yanfly Plugin Quest Jornal. But its to hard for me yet uhaahuahuh xD
Spoiler: code
Code:
 * @param Menu Help Windows
 * @type note[]
 * @desc
 * @default []
 *
 * @param Item Category Help Windows
 * @type note[]
 * @desc
 * @default []
    'use strict';
var Imported = Imported || {}; //import namespace
Imported.Eli_HelpWindowsStruct = true;

var Eli = Eli || {}; //author namespace
Eli.HelpWindowsStruct = Eli.HelpWindowsStruct || {};

var parameters = PluginManager.parameters('Eli_HelpWindowsStruct');

var MenuHelpText = String(parameters['Menu Help Windows']).split('[]');
var MenuHelp = JSON.parse(MenuHelpText);
var ItemCategoryHelpText = String(parameters['Item Category Help Windows']).split('[]');
var ItemHelp = JSON.parse(ItemCategoryHelpText);



    //SCENE MENU HELP - 955
    var EliHelp_Scene_Menu_create = Scene_Menu.prototype.create;
        Scene_Menu.prototype.create = function() {
            EliHelp_Scene_Menu_create.call(this);
                this.createHelpWindow();
        };

    //NEW FUNCTION
    Scene_Menu.prototype.createHelpWindow = function() {
        this._helpWindow = new Window_Help();
        this.addWindow(this._helpWindow);
        this._helpWindow.y = this._commandWindow.height;//324;
        this._helpWindow.x = 0;
        this._helpWindow.width = this._commandWindow.width;//730;
        this._helpWindow.height = Graphics.boxHeight - (this._commandWindow.height + this._goldWindow.height);
    };
   
    var EliHelp_Scene_Menu_update = Scene_Menu.prototype.update;
        Scene_Menu.prototype.update = function() {
            Scene_MenuBase.prototype.update.call(this);
                //this._helpWindow.setText(Eli.Param.HelpWindowsStruct.MenuHelpText[this._commandWindow._index]);
                this._helpWindow.setText(JSON.parse(MenuHelp[this._commandWindow._index]));
        };
       
    // SCENE ITEM HELP - 1215
    // NEW FUNCTION
    Scene_Item.prototype.update = function() {
        Scene_MenuBase.prototype.update.call(this);
            if (this._categoryWindow.active) {
                this._helpWindow.setText(JSON.parse(ItemHelp[this._commandWindow._index]));
            }
    };

Anyway, i managed it to work, in a... "ugly way". It worked perfect, but look at this.. auhuahuahuahuahua
Spoiler: image
vPml3u3.png
if at least in the plugin manager those things appear closed instead of wide open, it will be not so ugly.
I guess i will forgot this for the moment. Need to read more about the concepts of the language first to learn more. Then someday i get back to improvise this.
Thank you for all the help!!!😮‍💨

[[[EDIT]]]
_.regions = JSON.parse(_.params['Target Regions'] || '[]').map(Number);
I was looking at it too!! xD
These "._" made me a bit confused at first, but then I got it!
Wow... I always receive a crash when I JSON.parse an array 😀 But it's true I don't do it through the map command, I only did the raw parse 😅 Well, what you don't learn...
@Eliaquim oh I see, Scene_Item does not have a _commandWindow, I think you meant this._categoryWindow._index? 😮‍💨

You may find the console (F8) helpful in situations like this:
Code:
SceneManager._scene._commandWindow    // on Scene_Item returns undefined
SceneManager._scene._categoryWindow   // on Scene_Item returns window object

@Poryg well, you only parse strings, but any string starting/ending with square brackets[] should return an array, and anything in braces{} should return an object. E.g. in the console:
Code:
console.log(JSON.parse("[7,8,9]")[1]);   // returns 8: index 1 of parsed array
Plugin parameters are retrieved as strings, i.e. stringified values from the Plugin Manager; the editor parses them once to show them "normally", but you still see "quotes" in certain places, indicating that recursive parsing is needed for those types. 🙂
@Eliaquim oh I see, Scene_Item does not have a _commandWindow, I think you meant this._categoryWindow._index? 😮‍💨

You may find the console (F8) helpful in situations like this:
Code:
SceneManager._scene._commandWindow    // on Scene_Item returns undefined
SceneManager._scene._categoryWindow   // on Scene_Item returns window object

@Poryg well, you only parse strings, but any string starting/ending with square brackets[] should return an array, and anything in braces{} should return an object. E.g. in the console:
Code:
console.log(JSON.parse("[7,8,9]")[1]);   // returns 8: index 1 of parsed array
Plugin parameters are retrieved as strings, i.e. stringified values from the Plugin Manager; the editor parses them once to show them "normally", but you still see "quotes" in certain places, indicating that recursive parsing is needed for those types. 🙂
I don't believe that... hahahahah
This was the problem "this._categoryWindow._index" xD
Also i have to remove one ".map(JSON.parse)" for this work without errors!
Well, now i go to other scenes to see if i can make them all work.
Thanks a lot @caethyril !!! *____*

[EDITT] All working now, with the "note []" parameters!
Thanks for all the help you two *___*

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/plugin-parameters.108892/