MV Hey kids, don't forget that "=" and "==" are different.

If you're just getting into JavaScript, you might start getting fancy with your "Conditional Branches" and start using scripting instead of just the default values. When you do, it's really important to remember that "=" is the assignment operator, while "==" is the equality operator. "==" asks if two things are equal, while "=" overwrites the value on the assigned on the left with whatever value is on the right.

As an example, here's what took me literally hours to figure out this evening, because I forgot this simple fact.

1623661676941.png

This is bad. It forces the length of variable 312 (which is an array, though that's not really important) to become 0. It's bad for 2 reasons.
1. This isn't a question, so there isn't a chance for it to evaluate as true, which means that anything inside the if statement is never going to be done. In this case, that means an infinite loop, which is always just fantastic.
2. It overwrites whatever was in variable 312 with 0. In this case, since it's setting the length of variable 312 to zero, it's actually setting the value of 312 to [ ], removing all contents and making a mess of my evening that took hours of debugging and me being an idiot to sort out.

Here's what it was supposed to be
1623661974251.png

Now, it's actually checking the condition properly, and not overwriting the information with whatever garbage I accidentally turned it into.

Don't be like me kids. Always remember that "=" and "==" are different.
BONUS TIP:

If you're having issues debugging your code, try including some kind of heading with your debug messages, so that it's clear what part of your code you're actually in.

Repeating console.log($gameVariables.value(312)) after every single line makes it really difficult to which particular line is causing the problem. If you include a heading or some other information to easily differentiate between steps, you'll find your life much easier.
this level of detail explaining javascript if what i need.
if you could work together with Trihan and what they've already made, adding this level of detail in explaining all aspects of javascript it would be totally next level is helping a scripting full on noob like me understand what im actually looking at.
1. This isn't a question, so there isn't a chance for it to evaluate as true, which means that anything inside the if statement is never going to be done. In this case, that means an infinite loop, which is always just fantastic.
Actually, it's both an assignment and a question. If you hadn't set the length to 0, but to 1 (or any other number) instead, you would've always entered the conditional.

One cool thing about JavaScript (and most C-inspired languages), is that assignments also return a value. For example, you can do something like:
Code:
x = y = 0;
instead of:
Code:
x = 0;
y = 0;

You can also do something like:
Code:
if (this._isEnabled = result) {
   // do something
}
instead of:
Code:
this._isEnabled = result;
if (this._isEnabled) {
    // do something
}

I don't recommend using the second shortcut, because it's hard to tell if that's what you intended, or if it's a typo.

Also, JavaScript has two equality operators, == and ===. I recommend only using === and avoiding == if you can (https://stackoverflow.com/q/359494/1169228).
this level of detail explaining javascript if what i need.
if you could work together with Trihan and what they've already made, adding this level of detail in explaining all aspects of javascript it would be totally next level is helping a scripting full on noob like me understand what im actually looking at.
Have you tried any tutorials? Forget RPG Maker, just JavaScript tutorials. There are plenty that start at the beginner level.

Sites like javascript.info and w3schools.com have beginner tutorials, so they definitely cover very basic information like this. javascript.info is text-based, so you need to experiment on your own, but w3schools has code boxes on the page for you to type the examples into and see how they work.

These are just the first two things that come up when I Google "JavaScript tutorial."

Original thread: https://forums.rpgmakerweb.com/threads/hey-kids-dont-forget-that-and-are-different.137457/