I want to start scipting for MV

I have seen Java Script before, and I'm not completely new to it, but I see in the plugin scripts that it uses all these tags that I have never heard of before. I used to code at www.codecademy.com, but I don't think that makes me ready to script something for MV. 
Does anybody know where I can learn this?
I've moved this thread to Learning Javascript. Please be sure to post your threads in the correct forum next time. Thank you.
Well, I learned all of my MV scripting by looking at default code and the included .js plugins (they show how parameters should be set up and such) as well as looking at a couple Yanfly scripts.


Try going through some of the files in the /js/ folder of a new project, and I recommend looking at either TitleCommmandPosition or SimpleMsgSideView to get an idea of how parameters are imported, and looking at any of Yanfly's plugins to see how a more modification-friendly plugin should be set up.
I've moved this thread to Learning Javascript. Please be sure to post your threads in the correct forum next time. Thank you.

Ah, sorry. Thanks for moving it!! 🙂
CodeAcademy, to the best of my knowledge, starts by teaching you really basic 'get your feet wet' JavaScript, but really fails to teach you how to actually program. As a multi-paradigm functional and object oriented programming language, JavaScript is going to need more depth than CodeAcademy can get you. So, you know a little syntax- the next step is to learn how to program. Within a JavaScript context, my favorite text for that is Eloquent JavaScript, by Marijn Haverbeke. The RPG Maker context of JavaScript is a little different than a normal programming environment, and there are good practices that you discard in order to maintain community-level code compatibility, but most of that, you'll pick up by doing searches or talking to other programmers.
First, you need to have some idea how to program.


Then, you will need to figure out how to express your logic in Javascript.


If you already have Java experience, then you can probably just figure out how things are written in JS and go from there.


There are some things that might be a little strange, but you can figure them out as you go. Just the basic programming logic is enough:

  • Data types (number, string, array, object, function)
  • Math operations (addition, subtraction, multiplication, division, remainder)
  • Working with variables (variable scope and such)
  • Conditional branches (if, else if, else)
  • Loops (for loops, while loops)
  • Functions/methods
  • Classes (prototypes, inheritance, instance variables, etc)



If you have that down then that's more than enough to start making plugins.


Then you need an idea.


That's where you start.


Do not write code without a clear goal.


Define your requirements and how to determine whether you've accomplished them.

  • Want to build a new battle system? You can start there.
  • Want to create a new menu? That's also a starting point
  • Want to add new parameters for your battlers and use them in your damage formulas? Also an option.
  • Maybe a mini-game? Those are always fun and easy to distribute.



It doesn't matter where you start, as long as you get something done.


Look at other plugins and see the structure that they use. You can use that as a template and start from there, even if you don't understand the purpose.


I'd say it is more useful to get something working, than it is to understand why you're doing something a certain way.


Take things in steps: get something working, then go back and analyze what you did and why you did that.


After all, having something working is a validation that you can do it.
Make sure you got the basics covered first. For loops, if statements, switch statements, declaring variables, operators and comparisons. Hit up the code academy web site if you need to brush up. You may also want to study js classes, functions and data types to make more sense of the existing MV code.


Now the tricky bit is actually doing code for MV, because you are going to be using a lot of existing code and that can be intimidating. The simplest inline scripts you will likely start coding involve setting and reading values from game switches and variables. Example:

Spoiler
flag = true;
for (var i=21; i<30; i++) {
if (!$gameSwitches.value(i)) {flag = false}
}

if (flag) {
$gameSwitches.setValue(30,true);
}

This piece of code is an easier way to check if multiple switches are all set to true. In my case I'm checking switches 21 through 29 and if any one of them is false I turn my flag to false, but if they all checkout as true, then the flag stays true and I set the 30th game switch to true. To do this without scripting would involve a lengthy and repetitive sequence of checks.


To do even more interesting inline scripts you need to figure out and learn how the various game classes work. Some of the biggies like $gameSwitches, $gameVariables, $gameParty, $gameActor, $gameEnemy, $gameEvent.


The majority of the classes you will work with exist in rpg_objects.js, but an easier way to check the functionality of something (assuming you know it exists) is to wrap it in console.log() and check the output in the developer console by pressing F8 in game after the script is run. Example:


console.log($gameParty)


This will show a big list of functions and variables that are attached to $gameParty. You can then test out those functions and variables by wrapping them in a console.log to see if you used it correctly and what the result would be.


Lastly, you will wanna learn about the $data lists. They are representations of the json data that store all the crucial information about your classes, actors, maps, enemies and more. This is the information you put into the database and if you are ever comparing a variable against database information you will want to use the $data list associated to it instead of writing a hard coded comparison.This way if you ever change the database information it will reflect the changes in your code. Here is a simple example:

Spoiler
if (b.hp <= 0){
switch (b.originalName()) {
case $dataEnemies[1].name:
a.learnSkill(12);
break;
}
}

Here I am using the a/b notation for user/target and checking if the enemy I'm fighting has the same name as enemy ID 1 in my enemies list. If it is and I have killed the enemy then I want to learn its skill which is skill ID 12 in my skill list. The beauty here is that if I ever change the name of enemy 1 this code will still work since I am using the name from the database and not a hard coded name.
Lean the basic syntax of JavaScript and nuances exclusive to JavaScript first (I am assuming you already have some programming knowledge).  Where/how to learn is dependent on how serious you want to be as a JavaScript programmer.


If you do this, it will make it much easier to understand what MV is doing and will prevent you from running into issues that you would not have run into otherwise (these issues could cause hours upon hours of extra work).
Thanks for all the answers!


If you know about some books or websites that are teaching all these JS things that you have mentioned above, I would really like it if you could either post it here, or send me a PM 🙂
@Tyranida - If you are serious, I recommend some O'reilly books.


They have a ebook that is free to access (you can buy a hard copy to support the series if you want) here: https://addyosmani.com/resources/essentialjsdesignpatterns/book/


If you think this is to advanced for your level, then look under the Reading section of the link I provided (right before the Table of Contents section) for a good list of recommendations for books on the basics of JavaScript (they are all really good reads).


Hope this helps. 🙂

Original thread: https://forums.rpgmakerweb.com/threads/i-want-to-start-scipting-for-mv.56615/