TypeError: Cannot read property 'match' of undefined

I'm using Yanfly's Skill core.

Code:
<Before Eval>
if (target.isEnemy()) {

  var text = target.name() + '\n';
  text += '\\px[100]\\c[4]ATK:\\c[0] ' + target.atk;
  text += '\\px[300]\\c[4]MAT:\\c[0] ' + target.mat;
  text += '\n';
  text += '\\px[100]\\c[4]DEF:\\c[0] ' + target.def;
  text += '\\px[300]\\c[4]MDF:\\c[0] ' + target.mdf;
  $gameMessage.add(text);
}


for (var i = 1;i < 700;i++ ) {
var notedata = target.states(i).note;
if (target.isStateAffected(i)) {
   var text = target.states(i).name;
}
if (notedata.match("<Help Description>")) {
   text += "hello" ;
}
}

</Before Eval>

A beginner on Javascript.
Please teach me!
I am little dumb, please bear with me.
Sounds like you're referencing a state that doesn't exist.
Sounds like you're referencing a state that doesn't exist.
No, when I test it, there are two character, one of them use this skill, another one give enemy the state.
The .states() function returns an array so
Code:
target.states().note
Is trying to read the property "note" of an array. Arrays don't have properties, thus the error
The .states() function returns an array so
Code:
target.states().note
Is trying to read the property "note" of an array. Arrays don't have properties, thus the error

May I ask another question?
Another error comes: TypeError: Cannot read property 'match' of undefined.
Basically I want to make a skill to show enemy's param and states information.
Now I just need to check is it able to find "<Help Description>".
If not target.isStateAffected(i), notedata never gets assigned to, and is therefore undefined.
If not target.isStateAffected(i), notedata never gets assigned to, and is therefore undefined.
OK. Now I make it change a little bit, but same error appears.
Can you explain what you are trying to accomplish? It will help us understand your purpose, then we can help you better with the code.
Can you explain what you are trying to accomplish? It will help us understand your purpose, then we can help you better with the code.

Uh, it need to search the words between "<Help Description>" and "</Help Description>" in note and tell it to players.
Uh, it need to search the words between "<Help Description>" and "</Help Description>" in note and tell it to players.
if you need search a specific word , try use regex
https://regexr.com/
Uh, it need to search the words between "<Help Description>" and "</Help Description>" in note and tell it to players.
Which note:
For a skill? All skills in the database?
For a state? All states in the database?
Only if the character uses a certain skill?
Only if the character has a certain state?

Also, when you do this:
Code:
var notedata = target.states(i).note;
You're giving an argument to the 'states()' function, which does not take an argument.


Like Jon said, if you want to use the 'match' function it has to be for a Regular Expression.
Which note:
For a skill? All skills in the database?
For a state? All states in the database?
Only if the character uses a certain skill?
Only if the character has a certain state?

Also, when you do this:
Code:
var notedata = target.states(i).note;
You're giving an argument to the 'state()' function, which does not take an argument.


Like Jon said, if you want to use the 'match' function it has to be for a Regular Expression.
All states in database.
You want to tell the player the "Help Description" of every state in the database?

Ok, this is an outline of how you would do that:
Code:
for (var i = 1; i < $dataStates.length; i++ ) {
   var notedata = $dataStates[i].note;
   var match = notedata.match(//Regular Expression//);
   if (match) {
      text += match;
   }
}

You'll need to study the links that Jon and I shared to create the Regular Expression, and you can also study the Yanfly plugins to see how they do it.

Another option is to change your notetag structure to:
<Help: This is the help text about the state>

Then you can use the "meta" property of the data object and it doesn't require any Regular Expressions.

text += $dataStates.meta["Help"];
You want to tell the player the "Help Description" of every state in the database?

Ok, this is an outline of how you would do that:
Code:
for (var i = 1; i < $dataStates.length; i++ ) {
   var notedata = $dataStates[i].note;
   var match = notedata.match(//Regular Expression//);
   if (match) {
      text += match;
   }
}

You'll need to study the links that Jon and I shared to create the Regular Expression, and you can also study the Yanfly plugins to see how they do it.

Another option is to change your notetag structure to:
<Help: This is the help text about the state>

Then you can use the "meta" property of the data object and it doesn't require any Regular Expressions.

text += $dataStates.meta["Help"];

Thanks a lot.
I can say today I learned many things of JavaScript.

Original thread: https://forums.rpgmakerweb.com/threads/typeerror-cannot-read-property-match-of-undefined.91784/