Beginner Exploring Plugin Structure

Hello again,

I was suggested to look up how other members wrote their plugins so I decided to do just that (thank you @Restart). I've also been getting a lot of help from this wonderful community so I figured I would continue to seek my knowledge here.

The plugin I'd like to dissect is the following:
https://forums.rpgmakerweb.com/index.php?threads/iavra-text-sound.49347/

The way I'm planning to do this is to ask a simple question at a time and take things from there. I find that I learn better if I stick to small bit of information as opposed to trying to swallow huge concepts in a single shot.

At the very first lines of the plugin, we can see the following:
upload_2019-8-26_9-2-15.png

So first we have /* to comment out many lines. From what I've seen of other plugins, this is fairly typical of plugins in general. They all seem to start with this big square made out of asterisks (*).

My first question is:
Does the @ there means 'regarding' whatever. For example:
Regarding plugindesc (white space): description of what this line of code does.

I'll start with simple single simple questions and take it from there. Thank you.
Take it like this:
If you have all files in one folder, it makes it much harder to find the desired file than if they are separated: Images in image folder, plugins in plugin folder, etc. You can say these folders are separators to make it easier to find appropriate files.
And the @ is the same case. It's a separator that says that a new section of the plugin metadata is beginning. All this metadata is then visible in MV editor's plugin manager in some form.
Ah yes ok, makes sense. So @ makes metadata visible in the plugin editor. Interesting, I did not know that.

Question 2:
upload_2019-8-26_9-52-3.png

Is the highlighted || the same thing as the or operator or is it something else entirely?
Yes, it's the or operator. If Imported isn't defined, it will be a new object, otherwise it will be itself.
you'll see that method pretty commonly as a way of ensuring that you have a default value
To add on, being able to assign non-Boolean values to a variable using || is a quirk of JavaScript. If given a statement that's supposed to be true or false with values that are not literal Booleans of true or false, JavaScript takes its best guess as to whether the value is closer to true or closer to false. Most other languages don't do that.

null, undefined, 0, and empty strings evaluate to false, while most other things evaluate to true. We call the non-false values that JavaScript treats as false and vice versa "falsey" and "truthy".

So in JavaScript, a statement with the || operator is supposed to return the first truthy value, from left to right, or the last value if a truthy one isn't found.

So if Imported is defined, it's usually an object of some sort, which evaluates as truthy, so we end up saying, "var Imported = Imported". If it hasn't been previously defined, then Imported is undefined, which is falsey, so it goes to the next part of the or statement.

An empty object ({}) is truthy in JavaScript, so the statement stops there and says "var Imported = {}".
null, undefined, 0, and empty strings evaluate to false, while most other things evaluate to true. We call the non-false values that JavaScript treats as false and vice versa "falsey" and "truthy".
Yes, I did an exercise about that online recently. About 'truthy' and 'falsy' in JS.

index.php

One thing I've noticed is <Iavra Text Sound>. From what I can tell, <...> isn't a notation typically used with JS, isn't? Is it often used in the JS syntax because I haven't seen it very often so far.

As a slight tangent, would I be right to say that all of rpg maker (MV) events are essentially a frontend to Java Script, some sort of UI which allows the user to access pre-formated code so that he/she doesn't have to touch to scripting at all? Aren't all events basically call to scripts 'under the hood'?
As a slight tangent, would I be right to say that all of rpg maker (MV) events are essentially a frontend to Java Script, some sort of UI which allows the user to access pre-formated code so that he/she doesn't have to touch to scripting at all? Aren't all events basically call to scripts 'under the hood'?
Yep. The whole engine's source code is available, and you can dig up whatever any event calls.
index.php

One thing I've noticed is <Iavra Text Sound>. From what I can tell, <...> isn't a notation typically used with JS, isn't? Is it often used in the JS syntax because I haven't seen it very often so far.

It's not JS syntax at all. However, the RMMV engine allows users to use that syntax in noteboxes in the database to set a "meta" property on instances of actors, weapons, armor, items, events, enemies, etc.

The notebox for all the entries in the database is stored as a string as a property called "note" on that particular entry when it's turned into an object. That string is then parsed for that particular syntax, stripping away the < and >, then taking everything between them and converting all the characters before a colon into a key and everything after the colon into a value. These key-value pairs are then stored on the meta property.

Some developers also just parse all the text between "opening" and "closing" tags in the notebox in a way particular to their Plugin.

I'd take a couple screenshots to give some visual examples, but I'm traveling and don't have the engine on hand.

Try going to the first actor in your database, go to the notebox, then put:
Code:
<exampleMeta: Hello there!>

Then do a playtest, open up the developer console, type this code in, and hit enter:
Code:
$dataActors[0]

It should log an object representing the first actor in the database, which you can expand by clicking on the arrow next to it. Look for a property called "note" and a property called "meta" to see an example of how that syntax gets stored and converted.
I see. What you call that metadata? It's meta in what sense?
The description "notetag" here is being used as an identifier, so the plugin parameters can be correctly identified and loaded even if the plugin file is renamed. Relevant code excerpt:
Spoiler
Code:
    /**
     * Since PluginManager.parameters() breaks when the plugin file is renamed, we are using our own solution.
     */
    var _params = (function($) {
        return {
            enabled: $['Enable Text Sounds'].toLowerCase() === 'true',
            sound: $['Sound Name'],
            pan: parseInt($['Sound Pan']) || 0,
            pitch: parseInt($['Sound Pitch']) || 0,
            volume: parseInt($['Sound Volume']) || 0,
            interval: parseInt($['Interval']) || 1,
            limit: parseInt($['Limit']) || 0
        };
    })($plugins.filter(function(p) { return p.description.contains('<Iavra Text Sound>'); })[0].parameters);
^ Rather than referencing the plugin parameters directly by name, Iavra filters the list of currently-loaded plugins for those with "<Iavra Text Sound>" somewhere in their description, then grabs the parameters from the first plugin in that filtered list. The parameters are then passed into the IIFE as its first argument (named $ because it's short and easy to recognise).

Metadata is data that describes/informs other data. The <key: value> notetag format (text) has to be extracted from the relevant text fields on database objects and converted into actual code objects by string matching. The resultant metadata doesn't do anything alone, though: a plugin or script call is required to reference and act on that data in order to produce any effect. Hence, I think, "meta". 🙂
I see. What you call that metadata? It's meta in what sense?

Yes - and "meta" here just means "describing/referencing itself", so it's data about itself. So rather than, say, hp or mp, which are properties of an actor, the actor's metadata is data about that actor.

Although, as caethyril mentioned, the way it's being used in the section you originally highlighted is because normally for a Plugin to reference Plugin parameters, the .js file has to be named in a very exact way and the tag is instead being used as a way to make it agnostic about its own filename. It's just some unique text to search for in the description.
I understand some of your explanations but not all admittedly. I think I understand the general gist of it.

The issue with understanding computational linguistics lies in the vast amount of it and having to rely on its many constituents. What I mean by that is for example, suppose I ask why the < > are used in a code. The question itself is simple enough.

The problem is that the explanation involves references to other unknown concepts. For example:
Question: What is A?
Answer: A means B and C?
Question: What are B and C?
Answer: They mean a part of D and E...

and so on.

I looked up the meaning of parsing but it talked about concepts which I am not familiar with. Just to give you an idea, here's a list of things being talked about which are unfamiliar to me:
"...agnostic about its own filename"
"...are then passed into the IIFE as its first argument"
"Some developers also just parse all the text...
"These key-value pairs are then stored on the meta property." (I know what key-values are but I don't see what 'meta property' here means)

I think programming is something so technical that it's something difficult to vulgarize while remaining exact and non-misleading.
Okay, how's this?

RPG Maker has a built-in function which parses anything in a 'note' box, to make it easier for people using the rpg maker editor to add custom traits.

This function goes through and detects anything formatted as <propertyType: value>. It then creates the appropriate property/properties, and attaches them to whatever object the 'note' box represents.

For instance, if you open up Harold's note box in the editor, you can put in <Personality: Rude>. Then, when you open up the game, you can pull up Harold in $dataActors, and he'll have a meta property 'Personality' with the value 'Rude'. This isn't javascript per se, it's just a particular built-in function in the rpg maker engine.

Then you can use scripting or whatever to check to see if the leading character is Rude, and if so have different dialogue options.

Some plugin guys want to use their own system, so they'll scan it for something formatted the way they want, so they might have a plugin that scans an event for a comment that includes '{Highly Flammable}' or '[SecretWeaknesses] Ice, Fire, Baked Cheesecake[/SecretWeaknesses]', or '*~*sparkly*~*' or whatever other particular formatting they wanted to implement themselves. That's not particularly standardized, and the parsing code is implemented in the plugin itself.
It's clearer. I have a general understanding of it but I wouldn't be able to use < > if that makes any sense.

I don't understand what parsing means still though. To compile is to transform the data into something the computer can understand. But to parse? From what I can tell it's something not entirely different than to compile something but it's not the same either.

On the topic of plugins, explained simply, is there a reason why the structure looks so different when you open up a plugin and the libraries?

From rpg_scenes.js
upload_2019-8-28_23-15-58.png


From Iavra's plugin:
upload_2019-8-28_23-17-12.png

Could it be an option under Notepad++ or is it because a plugin and a library are very different? Just generally speaking I mean.
'parsing' in this case just means processing text according to some set of rules

like how this forum parses

Code:
[url=google.com][i]italic text[/i][/url]
to make
italic text

it parses the url and i tags in order to determine some extra stuff it needs to do (in this case, putting in a link and italics)
Just to give you an idea, here's a list of things being talked about which are unfamiliar to me:
"...agnostic about its own filename"
"The plugin is agnostic about its own filename" means "The plugin code does not care about what its file is named". This is not typically the case, e.g. Yanfly's Core Engine must be named YEP_CoreEngine.js in order for its parameters to be recognised. 🙂
"...are then passed into the IIFE as its first argument"
Oops, I thought someone had mentioned that earlier. 😅 An IIFE is an Immediately Invoked Function Expression. In other words, it's a function that is run once, when it is defined. E.g.
Code:
(function(text) {
  console.log(text);  // shows "Hello world!" in the console
})("Hello world!")
IIFEs are mostly a utility/code style thing. Details here: IIFE (MDN). 😤
"These key-value pairs are then stored on the meta property." (I know what key-values are but I don't see what 'meta property' here means)
meta is just another property on the database objects. You can access it like any other; elaborating on Restart's example, if you put a <Personality: Rude> tag in the notebox of actor 1 in the database, you can access that value at runtime (i.e. during gameplay) via this line of script:
Code:
$dataActors[1].meta.Personality
This will return the text "Rude", since that's the value associated with the "Personality" key here. 🙏
OMG!!!
I just learned so much on this topic. I love this forum!!
😍
On the topic of plugins, explained simply, is there a reason why the structure looks so different when you open up a plugin and the libraries?

I'm not really sure what you mean, those two screenshots both show valid Javascript. Are you asking why the second screenshot isn't highlighted with colors? That's a fault of the text editor (Notepad++) not properly highlighting colors on the syntax. You could fix that by using a different text editor or there's probably a plugin for Notepad++ to better show the colors (yes, plugin is a general term).

Original thread: https://forums.rpgmakerweb.com/threads/beginner-exploring-plugin-structure.112594/