How to build a nested array from a plugin parameter

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
I am working on a plugin where some of the parameters may contain arrays with a combination of numbers and strings.


Something like this works fine:

Code:
  var audioName = (params['Audio Name'] || '["My Audio Track", 80, 100]'
    ).replace(/[\[\]]/gi,'').split(",").map(function(value) {
    return eval(value);
  });
It gives me an array with ["My Audio Track", 80, 100] which is what I want.


But I also need to cater for the possibility that some of the content could be a nested array, such as this example for a font:

Code:
[["Tahoma", "Verdana", "Calibri"], 24, true, [0, 255, 0, 200]]
["Tahoma", 24, true, 15]
The first parameter could be just a string or an array of strings.  The last could be just a number or an array of numbers.


Not really sure how to go about this one.  Any suggestions?  I'd like to keep it fairly short.
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
if this plugin parameter my core have a method (it's open source to everyone :)


if this something else I don't know :C


NK.setArray = function(plugin, param){
return plugin[param].split(',').map( function (i) {return Number(i || 0);} );
};




for nested array well it's work mostly like the same than ruby?


you can do this : 


array.Method[0];


this will get the array inside I think in JS it's possible to get a data from his name ect....but still unsure  or this actually work like this : 


aray[0][0]




I hope this help :C
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
Thanks for your help, but I just figured out a super-easy solution while waiting for a response.  The following will convert a string to an array, complete with nested arrays and string, number or boolean conversion as necessary:

Code:
var myFontInfo = eval(params['Font Info'] || '[["Tahoma", "Verdana", "Calibri"], 24, true, [0, 255, 0, 200]]')


I was overthinking it.  Now to go back and change all the previous ones!
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
Thanks for your help, but I just figured out a super-easy solution while waiting for a response.  The following will convert a string to an array, complete with nested arrays and string, number or boolean conversion as necessary:

Code:
var myFontInfo = eval(params['Font Info'] || '[["Tahoma", "Verdana", "Calibri"], 24, true, [0, 255, 0, 200]]')


I was overthinking it.  Now to go back and change all the previous ones!
Oh nice! mind if I implement this method in my own core for nested array :D
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
go for it - it's not my method ;)
 

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

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

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.

Forum statistics

Threads
106,038
Messages
1,018,466
Members
137,821
Latest member
Capterson
Top