Array as Plugin command arguments

Heartbreak61

Wandering Noob
Veteran
Joined
Sep 5, 2012
Messages
187
Reaction score
90
First Language
Indonesian
Primarily Uses
RMMV
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!
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
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").
 

Galv

Veteran
Veteran
Joined
Oct 1, 2012
Messages
1,309
Reaction score
1,580
First Language
English
Primarily Uses
RMMZ
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 :)
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,316
Reaction score
537
First Language
indonesian
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.
 
Last edited by a moderator:

Heartbreak61

Wandering Noob
Veteran
Joined
Sep 5, 2012
Messages
187
Reaction score
90
First Language
Indonesian
Primarily Uses
RMMV
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 :D  .
 
@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  :D  
 

estriole

Veteran
Veteran
Joined
Jun 27, 2012
Messages
1,316
Reaction score
537
First Language
indonesian
 @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  :D  

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
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.
time for a new avatar :)

Forum statistics

Threads
106,018
Messages
1,018,357
Members
137,803
Latest member
andrewcole
Top