Parameter to String to Array of Number

I'm trying making a plugin... No, that's not right, I'm trying to convert a script into a plugin.


One of the things I'd need is to give the plugin an array. So I had the idea, give it in the form of a String, then call a function that splits the string into an array and then convert each element into a number into a second array.


Ok, plan ready, code written, time to test...


I have no idea why it says it is undefined. I changed and changed but it still says so.


I'm new at javascript, but I put var in front of every one of the variables but the function itself.


Could someone help?
Post the code - there are too many things you might have done wrong for us to even guess without seeing your code...
It's a little hard to help this way. Can you show your plugin?
It is an adaption of Hime's Skill Type Group. I sent her a message on her site asking for permission, and am working on it while she doesn't answer.


So, I claim no ownership of the original idea and base script.


//==============================================================================
// SkillTypeGroup.js
//==============================================================================

/*:
* @plugindesc Allows you to define skill groups based on skill type IDs.
* @author Hime (adapted by Yorae Rasante)
*
* @param Stype_Group
* @desc Main Skills Type of the group.
* @default 0
*
* @param Stype_Table
* @desc Skills Types of the group.
* @default 0
*
* @help ** Skill Type Groups
*/

var Imported = Imported || {};
Imported.TH_SkillTypeGroups = true;


(function() {
var parameters = PluginManager.parameters('SkillTypeGroup');
var StypeGroup = Number(parameters['Stype_Group'] || 0);
var StypeTable = String(parameters['Stype_Table'] || "");

var stlist = [];

StyleTableCalc = function() {
var list = StypeTable.split(',');
stlist = [];

for(var v = 0; v<list.length; v++)
{
stlist.push(Number(list[v]));
}
}

th_skill_type_groups_includes = Window_SkillList.prototype.includes;
Window_SkillList.prototype.includes = function(item) {
StyleTableCalc();
return item && (th_skill_type_groups_includes.call(this, item) || (this._stypeId === StypeGroup && stlist.includes(item.stypeId)));
};
})();


The idea is that StypeGroup is the one the others are grouped at, so as long as the window is for that skill type the ones of the types listed in StypeTable - and turned into an array of numbers on stlist - will appear on the window as if it was a member of it too.
Sadly, I could not spot a problem by looking at, can you help me to reproduce it? Like, what do I need to configure?


I never messed with skills and battle, but as no one else came, I can try to help if you want.


By the way, does not the console tells which line is the problem in?
It says, but... the message is "undefined is not a function", and the lumber points to being the part about stlist.includes(item.stypeId).


So ok, I changed it a bit. Put a function there, and fixed the function name on the way.


//==============================================================================
// SkillTypeGroup.js
//==============================================================================

/*:
* @plugindesc Allows you to define skill groups based on skill type IDs.
* @author Hime (adapted by Yorae Rasante)
*
* @param Stype_Group
* @desc Main Skills Type of the group.
* @default 0
*
* @param Stype_Table
* @desc Skills Types of the group.
* @default 0
*
* @help ** Skill Type Groups
*/

var Imported = Imported || {};
Imported.TH_SkillTypeGroups = true;


(function() {
var parameters = PluginManager.parameters('SkillTypeGroup');
var StypeGroup = Number(parameters['Stype_Group'] || 0);
var StypeTable = String(parameters['Stype_Table'] || "");

var stlist = [];

StypeTableCalc = function() {
var list = StypeTable.split(',');
stlist = [];

for(var v = 0; v<list.length; v++)
{
stlist.push(Number(list[v]));
}
return stlist;
}

th_skill_type_groups_includes = Window_SkillList.prototype.includes;
Window_SkillList.prototype.includes = function(item) {
return item && (th_skill_type_groups_includes.call(this, item) || (this._stypeId === StypeGroup && StypeTableCalc().includes(item.stypeId)));
};
})();


Same thing. But this time it is about StypeTableCalc, which is a function...


To reproduce it... I created two new skill types in the database, then added the old magic's number to StyleGroup and the new to StyleTable on the plugin editor.


Then created a skill under one of the new skill types.


If it worked, the new skill should appear under the old magic list too. But instead it gives the error message.
can you give the full console output as a screenshot? not only the last line with the error message, but every line?


That would at least tell us what else is involved in this.
Here, sorry.


There are a few more lines than the ones I shared here, but they are mostly Hime's script disclaimer that I added for me to send to her when I finish, since it is based on her work I thought she'd like me to add them.

consolesc.png
Test this

Code:
(function() {
	var parameters = PluginManager.parameters('SkillTypeGroup');
	var StypeGroup = Number(parameters['Stype_Group'] || 0);
	var StypeTable = String(parameters['Stype_Table'] || "").split(',');
    
	var th_skill_type_groups_includes = Window_SkillList.prototype.includes;
	Window_SkillList.prototype.includes = function(item) {
		return th_skill_type_groups_includes.call(this, item) || (item && this._stypeId === StypeGroup && StypeTable.indexOf('' + item.stypeId) > -1);
	};
})();
It is giving no errors anymore, that's an improvement. Also, didn't know about indexOf.


Thanks.


But it doesn't seem to work yet either...


As a side-question, do I need to refresh every time I change the script? I'm doing so, but it is a bit annoying...
What happens? Nothing?


Is it the last imported plugin in your project?


Use this, and show us the console again please.


(function() {
var parameters = PluginManager.parameters('SkillTypeGroup');
var StypeGroup = Number(parameters['Stype_Group'] || 0);
var StypeTable = String(parameters['Stype_Table'] || "").split(',');

var th_skill_type_groups_includes = Window_SkillList.prototype.includes;
Window_SkillList.prototype.includes = function(item) {
console.log('=x=x=');
console.log(item);
console.log('-----');
console.log(this._stypeId === StypeGroup);
console.log('-----');
console.log(StypeTable);
console.log('=x=x=');
return th_skill_type_groups_includes.call(this, item) || (item && this._stypeId === StypeGroup && StypeTable.indexOf('' + item.stypeId) > -1);
};
})();




About the side question: yes, just use F5 on the game after saving the plugin file.
There are no skills on that window (mind you, the testing skill is the only one that should appear but still...)


Yes, the last one.


This is the relevant one, about the skill that should appear.


consolesc.png
There are spaces in your StypeTable, when you define the plugin parameters remove the spaces, like:


12,13,14 instead of 12, 13, 14
Ah...


I was just yesterday thinking about how to remove the spaces, and I ended up forgetting... thank you.


This part is working just as I wanted. Now for the skill notes part.


Now that I know what I did wrong, I think it should go much better. Thanks again.
Glad to help  😀
Ok, this is a bit different...


Hope no one minds me reusing the thread.


Since you can use the MadeWithMv multiple times, I thought there would not be a problem using this plugin twice or more, once for each group. But only the first use is appearing...


I didn't even remove the console commands from the plugin yet, but the second one doesn't appear in the console.
Sorry I dont understand,  MadeWithMv ? Looks like it's related to a specific plugin support.


I see you speak portuguese, you can send me PM if you want, maybe it's easier to understand.
Sorry, my internet is not good right now.


That is the name for the standard Splash Screen plugin. The one that comes active in every new project as far as I know.


But again, not surprised you forgot the name. I had to check the name to type it else I'd just put splash screen there.


I don't mind, but wouldn't it be better to do it here so others with the same doubt can find it too?
Actually I think I understood your problem.


You want to create more skill groups importing the plugin many times and changing the parameters, right?


This won't work the way it is, you'll need to think another way to place the groups, like using skill note tags.


A simple option is to create anoter separator and split the parameter string again (ugly but works :s), like:


10,11,12|13,14,15|16,17,18


then do .split('|') and for each result do split(',')


So "|" means group separator and "," means group item separator.
Oh... I was worried it would be so... Knowing that the splash screen plugin could be repeated gave me hope, but if it can't be done...


Oh well, it was a learning experience.


I'll have to use only the skill note tags then. At least I was going to add the option of using them anyway.


It'll make things harder for whoever use the plugin in the future, but if that's all that can be done...


[Edit]Just saw your edit, I'll try it! Thanks again.

Original thread: https://forums.rpgmakerweb.com/threads/parameter-to-string-to-array-of-number.68214/