RPGMakerMV Creating And Reading Note Tags

Introduction

Many times in RPGMaker MV when creating plugins you’ll want data from the developer about an item, character, etc; we can get that data using note tags.

Here’s an example of a note tag.

Example

That note tag is used to return a number to the JavaScript plugin when looking through the game skills. Now, there are two ways to read the data; using the meta property on every data object, or by using regular expressions in note tag. Regular expressions are the most effective and creative way of reading note tags, which we’ll cover today.

Regular Expressions

Regular expressions are used in JavaScript for parsing data from formatted text by matching a text pattern against the formatted text. Now, the topic of regular expressions is as deep as throwing a penny down a well hoping to hear it go ‘clank’. Instead, we’ll be focusing on the core principle, flags, and special characters that you’ll need to know.

The Principle

Regular expressions are patterns by combining flags and special characters for formatting to get data from text.

Flags

  • g (Checks all the text in the string, instead of giving up after the first match)
  • i  (Ignores capital and lowercase letters; considers them equal)

Special Characters

  • * (Character can occur 0 or more times)
  • + (Character can occur 1 or more times)
  • ? (Character can occur 0 or 1 times)
  • \s (Matches any space characters: ‘ ‘, ‘\r’, \t’, ‘\l\r’)
  • \w (Matches any word character: A-z)
  • \d (Matches any digit character: 0 – 9)
  • () (Used to capture data from the text; known as a capture group)

 

Combining the three ideas into a completely wrapped package, we can move on to creating regular expressions for reading note tags.

Creation

Here’s an example of a couple for the above screenshot.

Example

Pattern 1 combines ‘\s‘ with ‘‘; this means you can have optional spaces between the characters. Then we have the capture group ‘(\d+.\d*)‘; this means to get any digits optionally followed by a ‘.’ and more digits.

Pattern 2 is the same exact pattern without ‘\s*‘; this means the matching is extremely strict and you can’t have optional spaces.

Now, how do we read note tags effectively?

Reading

To read a note tag in our JavaScript code is simple once we’ve created our regular expression. The easiest way is to use the RegExp.exec() method which returns a result array if there is a match or null.  

Here’s an example to read the note tag in the above screenshot from the skills data.

Example

This function goes through each skill in RPGMaker MV, looks at the note box text, and then compares it to our regular expression. If there’s a match, we send the result to the console.

Here’s the result in the RPGMaker MV console.

Result

Conclusion

These are basic tools you’ll be using when constructing regular expressions of reading your own note tags. I hope this helped you. If you think it can help someone else, share it on your favorite platforms.

Have a wonderful day!

Sources

MDN Regular Expressions

MDN RegEx Class

 

Leave a Reply

Your email address will not be published.