Array as Plugin command arguments

Hi guys

I am developing a simple plugin that requires user to have specific setup using array. Its something like

var foo = {// [ a, b, c, ...] <- a comment so user have an idea about what value modifies what thing 1: [ 1, 2, 3, ...], 2: [ 4, 5, 6, ...], //etc};Back in VXA, I believe I've seen this kind of setup. But now, since the existence of Plugin Event Command and Plugin Parameters, is this kind of setup generally accepted? I mean, get the user to setup things directly inside the *.js files?

I think writing a long array as Plugin Event Command argument kind of un-user friendly. I know that I could ask user to edit a specified JSON files, but I think it will means more work to do for the user since basically my object is very simple object.

I will appreciate any kind of suggestion regarding this matter.

Thanks!
What do you want to achieve? You can parse plugin parameters to be interpreted as arrays, like this:

Code:
var paramArray = param.split(/\s*,\s*/).filter(function(val) { return !!val; });
This will split the given string at commas, discarding whitespaces around the comma and removing empty elements afterwards (like "a,,b").
I've been writing a plugin that requires a lot of setup from users, too. I am currently using an external txt file that users use to set up their data.


Would love to hear if anyone has any better ideas to approach this, too 🙂
http://forums.rpgmakerweb.com/index.php?/topic/50347-emoji-engine-mv-origin-plugincore/ dat o3o

it's setup all stuff for your plugin params 

you can put the method out of the function if you want for not having plugin dependencies.
in my plugin here:

http://forums.rpgmakerweb.com/index.php?/topic/49350-est-auto-text-color-plus/

i use plugin parameter.

@param Starting_Entry 1@desc Format: Yourtext; coloridseparate them with semi colon ( @default Nobita; 2 @param Starting_Entry 2@desc Format: Yourtext; coloridseparate them with semi colon ( @default Doraemon; 3edit: damn... the text i write is missing... what happened???

here's it is.

i grab parameter above with:

var EST = EST || {};EST.AutoColor = EST.AutoColor || {}; EST.AutoColor.param = $plugins.filter(function(p) {     return p.description.contains('<EST_AUTO_TEXT_COLOR_PLUS>'); })[0].parameters;EST.AutoColor.setting = EST.AutoColor.setting || {}; for (key of Object.keys(EST.AutoColor.param)){    if (key.match(/Starting_Entry/im) && EST.AutoColor.param[key] != "")     {        var entry = EST.AutoColor.param[key].split(/\s+;\s+|;\s+|\s+;|;/);        EST.AutoColor.setting[entry[0]] = Number(entry[1]);    }}so user can easily enter parameter key => value.

i set it to have 30 entry which if not filled ("") will be not added to the hashlike object...

and if it's not enough for the developer. i give them way to increase it.

first i store it in $gameSystem... then they can add it by:

using plugin command.

//alias method to create plugin command  var est_auto_color_GameInterpreter_pluginCommand =                Game_Interpreter.prototype.pluginCommand;   Game_Interpreter.prototype.pluginCommand = function(command, args) {    est_auto_color_GameInterpreter_pluginCommand.call(this, command, args);     if (command.toUpperCase() === 'UPDATE_AC_ENTRY')       {       var setting = args.join(" ").split(/\s+;\s+|;\s+|\s+;|;/);       $gameSystem.add_AC_Entry(setting[0],Number(setting[1]));      };  };Game_System.prototype.add_AC_Entry = function(name, color) {    this._AC_setting[name] = color;};thus they can add / update entry with:

plugin command:

UPDATE_AC_ENTRY estriole cool   ;   8if your case... you might have to parse the array either with eval or JSON.parse.

it's easier for user to modify plugin parameter than editing js file.
Thank you!

What do you want to achieve? You can parse plugin parameters to be interpreted as arrays, like this:

var paramArray = param.split(/\s*,\s*/).filter(function(val) { return !!val; });This will split the given string at commas, discarding whitespaces around the comma and removing empty elements afterwards (like "a,,b").
http://forums.rpgmakerweb.com/index.php?/topic/50347-emoji-engine-mv-origin-plugincore/ dat o3o

it's setup all stuff for your plugin params 

you can put the method out of the function if you want for not having plugin dependencies.
Well, I'm asking about user friendliness here, not a method about how to get user's argument.
 
My  problem is, my array consist of 11 elements (and could be more). I think, asking users to write 12 arguments (including keys) without any "hint" (on my first post, users will easily tell that they will modify "a" by value 1 and 4).
 
 

I've been writing a plugin that requires a lot of setup from users, too. I am currently using an external txt file that users use to set up their data.
Would love to hear if anyone has any better ideas to approach this, too 🙂
Yeah, I've thought about using this kind of approach. Indeed a very nice approach for complex object. But I think, for my simple plugin, this kind of approach will introduce more difficulties to the user 😀  .
 
@Est: What if you want user to write 

Doraemon; 3; 42; 60; 70; 100; 90; 180; 300; 200; 125; 331

I'm creating a table with many columns but few rows here  😀  
 @Est: What if you want user to write 

Doraemon; 3; 42; 60; 70; 100; 90; 180; 300; 200; 125; 331

I'm creating a table with many columns but few rows here  😀  

Thank you!
in plugin parameter? or in plugin command?

also i assume you want the Doraemon as key... then all other as value?

it would be easier if you do it like this:

Doraemon; [3,42,60,70,100,90,180,300,200,125,331]

in parameter:

grab it first so you get above string...

then split the string with ; then you get array with 2 member.

0) Doraemon

1) [3,42,60,70,100,90,180,300,200,125,331]

then JSON.parse the array[1] to make it array object instead of string.

example:

//initialize ESTvar EST = EST || {};// Initialize EST.AutoColorEST.AutoColor = EST.AutoColor || {}; //Grab parameterEST.AutoColor.param = $plugins.filter(function(p) {    return p.description.contains('<EST_AUTO_TEXT_COLOR_PLUS>'); })[0].parameters;//Initialize EST.AutoColor.settingEST.AutoColor.setting = EST.AutoColor.setting || {}; //Loop all parameter key's for (key of Object.keys(EST.AutoColor.param)){    if (key.match(/Starting_Entry/im) && EST.AutoColor.param[key] != "")    {        var entry = EST.AutoColor.param[key].split(/\s+;\s+|;\s+|\s+;|;/);        EST.AutoColor.setting[entry[0]] = JSON.parse(entry[1]);          //entry[0] => "Doraemon" entry[2] => [3,42,60,70,100,90,180,300,200,125,331]    }}
for plugin command it's basically the same

Original thread: https://forums.rpgmakerweb.com/threads/array-as-plugin-command-arguments.50736/